Reputation: 495
I've build one small code using graphql, nodejs, express and sequelize (with mysql) but I'm can't find the magic of graphql yet. I'd create my models using sequelize-cli (using sequelize model:create etc.) and I'd generating dynamically my schemas and types like that:
var types = generateModelTypes([db['User'], db['Acesso']])
var schema = generateSchema({User: db['User'], Acesso: db['Acesso']}, types)
And I'd opened my app on the follow way:
app.use(
'/graphql',
graphqlHTTP({
schema: schema,
graphiql: true
})
)
app.listen(4000, function (){
console.log("Calling app.listen's callback function.");
})
But I can't send one query on graphiql using that:
curl -X POST -H "Content-Type:application/json" -d '{ "query": "{ users { id } }" }' localhost:4000/graphql
I get this error:
{"errors":[{"message":"Expected [object Object] to be a GraphQL schema."}]}
What I doing wrong!?
Upvotes: 0
Views: 769
Reputation: 84867
Looking at the documentation for graphql-sequelize-schema-generator
, the generated schema isn't actually an instance of GraphQLSchema, so you need to do something like this:
schema: new GraphQLSchema(schema)
Upvotes: 1