Skip to content

Instantly share code, notes, and snippets.

@robzhu
Created September 8, 2017 15:55
Show Gist options
  • Save robzhu/2182cfbb17189d4163001e7164a4cea7 to your computer and use it in GitHub Desktop.
Save robzhu/2182cfbb17189d4163001e7164a4cea7 to your computer and use it in GitHub Desktop.
GraphQL "type" field name repro
const {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLList,
} = require('graphql');
const helloType = new GraphQLObjectType({
name: 'helloType',
fields: () => ({
name: {
type: GraphQLString,
resolve: ({name}) => name,
},
type: {
type: GraphQLString,
resolve: ({type}) => type,
}
})
});
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'query',
fields: {
hello: {
type: helloType,
resolve: () => {
return {
name: 'hello-field-name',
type: 'hello-field-type'
};
}
}
}
})
});
module.exports = schema;
// Test query:
query {
hello {
name
type
}
}
// Test query response:
{
"data": {
"hello": {
"name": "hello-field-name",
"type": "hello-field-type"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment