Skip to content

Instantly share code, notes, and snippets.

@tenzan
Created October 4, 2018 14:37
Show Gist options
  • Save tenzan/c619b95855ad527dccdd950d0451f23f to your computer and use it in GitHub Desktop.
Save tenzan/c619b95855ad527dccdd950d0451f23f to your computer and use it in GitHub Desktop.
Section 3, Lecture 9: First GraphQL Server - Part 2
const { makeExecutableSchema } = require('graphql-tools');
const { graphql } = require('graphql');
const typeDefs = `
schema = {
query: Query
}
type Query {
hello: String
}
`;
const resolvers = {
Query: {
hello: () => 'World'
}
};
const schema = makeExecutableSchema({ typeDefs, resolvers });
const query = process.argv[2];
graphql(schema, query).then(result => {
console.log(JSON.stringify(result, null, 2));
});
@tenzan
Copy link
Author

tenzan commented Oct 4, 2018

Error message when executing node index.js "query { hello }"

/Users/askar/work/graphql/graphql-for-beginners-with-javascript/helloworld/node_modules/graphql/language/parser.js:1463
throw (0, _error.syntaxError)(lexer.source, token.start, "Expected ".concat(kind, ", found ").concat((0, _lexer.getTokenDesc)(token)));
^
GraphQLError: Syntax Error: Expected {, found =
at syntaxError (/Users/askar/work/graphql/graphql-for-beginners-with-javascript/helloworld/node_modules/graphql/error/syntaxError.js:24:10)
at expect (/Users/askar/work/graphql/graphql-for-beginners-with-javascript/helloworld/node_modules/graphql/language/parser.js:1463:32)
at many (/Users/askar/work/graphql/graphql-for-beginners-with-javascript/helloworld/node_modules/graphql/language/parser.js:1519:3)
at parseSchemaDefinition (/Users/askar/work/graphql/graphql-for-beginners-with-javascript/helloworld/node_modules/graphql/language/parser.js:768:24)
at parseTypeSystemDefinition (/Users/askar/work/graphql/graphql-for-beginners-with-javascript/helloworld/node_modules/graphql/language/parser.js:718:16)
at parseDefinition (/Users/askar/work/graphql/graphql-for-beginners-with-javascript/helloworld/node_modules/graphql/language/parser.js:142:16)
at many (/Users/askar/work/graphql/graphql-for-beginners-with-javascript/helloworld/node_modules/graphql/language/parser.js:1520:16)
at parseDocument (/Users/askar/work/graphql/graphql-for-beginners-with-javascript/helloworld/node_modules/graphql/language/parser.js:113:18)
at Object.parse (/Users/askar/work/graphql/graphql-for-beginners-with-javascript/helloworld/node_modules/graphql/language/parser.js:48:10)
at Object.buildSchemaFromTypeDefinitions (/Users/askar/work/graphql/graphql-for-beginners-with-javascript/helloworld/node_modules/graphql-tools/dist/generate/buildSchemaFromTypeDefinitions.js:19:33)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment