I’m using the excellent Kadira LearnGraphQL site, and learning a lot. At the same time, in Lesson 9 there’s some sample code that I haven’t gotten to work yet. If I’m following the lesson correctly, this is the sample code:
import {
// These are the basic GraphQL types
GraphQLInt,
GraphQLFloat,
GraphQLString,
GraphQLList,
GraphQLObjectType,
GraphQLEnumType,
// This is used to create required fields and arguments
GraphQLNonNull,
// This is the class we need to create the schema
GraphQLSchema,
// This function is used execute GraphQL queries
graphql
} from 'graphql';
const Query = new GraphQLObjectType({
name: 'RootQueries',
fields: () => ({
echo: {
type: GraphQLString,
args: {
message: {type: GraphQLString}
},
resolve(rootValue, args) {
return `received: ${args.message}`;
}
}
})
});
const Schema = new GraphQLSchema({
query: Query
});
let query = `
query getEcho($inputMessage: String) {
receivedMessage: echo(message: $inputMessage)
}
`;
graphql(Schema, query, null, {inputMessage: "Hello"}).then(function(result) {
console.log(result);
});
When I run the code, I get:
{ data: { receivedMessage: ‘received: undefined’ } }
… instead of:
{ data: { receivedMessage: ‘received: Hello’ } }
What am I missing?