I need some help to solve an error on graphql, I can't find anything on this case.
I tried to separate my different schemas and resolvers to make it easier to maintain, but when I use makeExecutableSchema function (from graphql-tools package), a "GraphQLError: Syntax Error: Unexpected Name "User"" error is throw.
So here is the Error :
/Users/thomasblanquet/EIP_Routs/API/routs-api/node_modules/graphql/language/parser.js:153
throw unexpected(lexer);
^
GraphQLError: Syntax Error: Unexpected Name "User"
at syntaxError (/Users/thomasblanquet/EIP_Routs/API/routs-api/node_modules/graphql/error/syntaxError.js:24:10)
at unexpected (/Users/thomasblanquet/EIP_Routs/API/routs-api/node_modules/graphql/language/parser.js:1490:33)
at parseDefinition (/Users/thomasblanquet/EIP_Routs/API/routs-api/node_modules/graphql/language/parser.js:153:9)
at many (/Users/thomasblanquet/EIP_Routs/API/routs-api/node_modules/graphql/language/parser.js:1523:16)
at parseDocument (/Users/thomasblanquet/EIP_Routs/API/routs-api/node_modules/graphql/language/parser.js:113:18)
at Object.parse (/Users/thomasblanquet/EIP_Routs/API/routs-api/node_modules/graphql/language/parser.js:48:10)
at Object.buildSchemaFromTypeDefinitions (/Users/thomasblanquet/EIP_Routs/API/routs-api/node_modules/graphql-tools/dist/generate/buildSchemaFromTypeDefinitions.js:19:33)
at makeExecutableSchema (/Users/thomasblanquet/EIP_Routs/API/routs-api/node_modules/graphql-tools/dist/makeExecutableSchema.js:26:29)
at Object.<anonymous> (/Users/thomasblanquet/EIP_Routs/API/routs-api/graphql/schema.js:15:18)
at Module._compile (internal/modules/cjs/loader.js:689:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
And here is my code :
For the User schema :
const User = `
User {
_id: Int!
username: String!
email: String!
}
extend type Query {
users: [User]
}
`;
module.exports = User;
For the resolver (the model is create with sequelize and I'm using Apollo-Server-Express):
const User = require('../../server/models/user')
const Messages = require('../messages');
const resolvers = {
Query: {
users(parent, args, context, info) {
parent.getUsers()
},
};
module.exports = resolvers;
And finally the code to put the schemas and resolvers together :
const { makeExecutableSchema } = require('graphql-tools');
const resolvers = require('./resolver');
const User = require('./user/schema');
const Query =
`type Query {
_empty: String
}`;
const Mutation =
`type Mutation {
_empty: String
}`;
module.exports = makeExecutableSchema({
typeDefs: [Query, Mutation, User],
resolvers,
});
I really can't find anything about this kind of problem, thanks for helping me :)