Created
September 8, 2017 15:55
-
-
Save robzhu/2182cfbb17189d4163001e7164a4cea7 to your computer and use it in GitHub Desktop.
GraphQL "type" field name repro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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