sarkistlt / mongoose-schema-to-graphql

Use Mongoose schema to generate graphQL type.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

1:1 Help

astrotars opened this issue · comments

Would you be open to a 1:1 Google Hangout for pay? Need some help. Running into several issues. Thanks! Please ping me here and we can set something up. Thanks!

Hi, You can mention all issues here, I'll try to help you today/tomorrow, will be usufull for others too.

I simply receive Error: Schema must be an instance of GraphQLSchema. Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory. which is very frustrating. It's as if the library isn't exporting a valid schema. Any thoughts or have you run into this before? It's a vague question, given the reason I didn't want to ask here.

hm, sound weird, can you please copy/past your dependence + dev from package.json?

and code snippet where are you using this module + snippet where are you declarating graphql schema itslef.

I'm using Apollo with express.

Deps:

https://gist.github.com/nparsons08/1f074c0179d8fd32d694226adbf8377e'

server.js:

import express from 'express'
import bodyParser from 'body-parser'
import { graphiqlExpress, graphqlExpress } from 'graphql-server-express'

import schema from './data/schema-v2.js'
//import mocks from './data/mocks'
import config from './config'

let app = express()

app.use('/graphiql', graphiqlExpress({
    endpointURL: '/'
}))

app.use('/', bodyParser.json(), graphqlExpress({
    schema: schema,
    //mocks: mocks,
}))

app.listen(config.server.port, (err) => {
    if (err) {
        return console.error(err)
    }
    console.log(`GraphQL server is now running on port ${config.server.port}`)
})

schema-v2.js:

import createType from 'mongoose-schema-to-graphql'

import { userSchema } from './models/user'

let config = {
    name: 'userType',
    description: 'User collection model',
    class: 'GraphQLObjectType',
    schema: userSchema
}

export default createType(config)

Hi, of curse it won't work, in schema-v2.js is not a schema it is graphQL type which you need to use to create all your graphql queries and mutations then create Schema. I would suggest you to take a look to graphql docs, how it works.