I'm having troubles with referencing to other GraphQLObjectTypes inside a GraphQLObjectType. I keep getting the following error:
"message": "The type of getBooks.stores must be Output Type but got: undefined."
I thought that using a resolve inside books.stores would help fixing the issue, but it doesn't. Can someone help me out?
Code
var express = require('express');
var graphqlHTTP = require('express-graphql');
var graphql = require('graphql');
var { buildSchema, GraphQLSchema, GraphQLObjectType,GraphQLString,GraphQLList } = require('graphql');
var books = new GraphQLObjectType({
name:'getBooks',
fields: {
isbn: { type: GraphQLString},
stores: {
type: stores,
resolve: function(){
var store = [];
store.storeName = "this will contain the name of a shop";
return store;
}
}
}
});
var stores = new GraphQLObjectType({
name:'storeList',
fields: {
storeName: { type: GraphQLString}
}
});
var queryType = new GraphQLObjectType({
name: 'Query',
fields: {
books: {
type: books,
// `args` describes the arguments that the `user` query accepts
args: {
id: { type: new GraphQLList(GraphQLString) }// graphql.GraphQLStringj
},
resolve: function (_, {id}) {
var data = [];
data.isbn = '32131231';
return data;
}
}
}
});
var schema = new GraphQLSchema({query: queryType});
var app = express();
app.use('/graphql', graphqlHTTP({
schema: schema,
graphiql: true,
}));
app.listen(4000);
console.log('Running a GraphQL API server at localhost:4000/graphql');
It couldn't find stores because it was defined after books. So I placed the stores code before books.