If a customer does not know the schema and would like to introspect and understand a GraphQL API, it seems that GraphQL may not be able to support the recursive introspection. See the following example about my point
First of all, the following is my schema definition at high level:
// schema.js
...
...
const AuthorType = new GraphQLObjectType({
name: "Author",
description: "This represent an author",
fields: () => ({
id: {type: new GraphQLNonNull(GraphQLString)},
name: {type: new GraphQLNonNull(GraphQLString)},
twitterHandle: {type: GraphQLString}
})
});
const PostType = new GraphQLObjectType({
name: "Post",
description: "This represent a Post",
fields: () => ({
id: {type: new GraphQLNonNull(GraphQLString)},
title: {type: new GraphQLNonNull(GraphQLString)},
body: {type: GraphQLString},
author: {
type: AuthorType,
resolve: function(post) {
return _.find(Authors, a => a.id == post.author_id);
}
}
})
});
// This is the Root Query
const BlogQueryRootType = new GraphQLObjectType({
name: 'BlogAppSchema',
description: "Blog Application Schema Query Root",
fields: () => ({
authors: {
type: new GraphQLList(AuthorType),
description: "List of all Authors",
resolve: function() {
return Authors
}
},
posts: {
type: new GraphQLList(PostType),
description: "List of all Posts",
resolve: function() {
return Posts
}
}
})
});
When someone queries the schema using the following query clause:
{
__type(name: "BlogAppSchema") {
name
fields {
name
description
type {
name
}
}
}
}
She gets the following result:
{
"data": {
"__type": {
"name": "BlogAppSchema",
"fields": [
{
"name": "authors",
"description": "List of all Authors",
"type": {
"name": null
}
},
{
"name": "posts",
"description": "List of all Posts",
"type": {
"name": null
}
}
]
}
}
}
Reading the source code, we know that authors are a list of AuthorType. But how can a user, not having access the source code, further introspect the field of 'authors' from the results she got above (the type field shows "null" here)? She does not seem to be able to know authors is a list of Author from the above result. Is there a way for her to further introspect?