| Based off this post on the apollo blog: https://blog.apollographql.com/three-ways-to-represent-your-graphql-schema-a41f4175100d It's possible to use GraphQL's internal buildSchema function. This function fails with really informative syntax errors when invalid schemas are supplied. I suggest we used this on the admin UI side to validate incoming user schemas. Take a look at the example usage from the blog post:
const { buildSchema } = require('graphql'); |
|
const sdlSchema = ` |
type Author { |
firstName: String |
lastName: String |
} |
type Query { |
author(id: Int!): Author |
} |
`; |
|
const graphqlSchemaObj = buildSchema(sdlSchema);
|
If we break the syntax slightly we get the following output:
Syntax Error: Expected :, found Name "Author" |
|
GraphQL request (7:22) |
6: type Query { |
7: author(id: Int!) Author |
^ |
8: } |
|
at syntaxError (/Users/dara/mcp/aerogear-data-sync-server/node_modules/graphql/error/syntaxError.js:24:10) |
at expect (/Users/dara/mcp/aerogear-data-sync-server/node_modules/graphql/language/parser.js:1299:32) |
at parseFieldDefinition (/Users/dara/mcp/aerogear-data-sync-server/node_modules/graphql/language/parser.js:811:3) |
at many (/Users/dara/mcp/aerogear-data-sync-server/node_modules/graphql/language/parser.js:1348:16) |
at parseFieldsDefinition (/Users/dara/mcp/aerogear-data-sync-server/node_modules/graphql/language/parser.js:799:50) |
at parseObjectTypeDefinition (/Users/dara/mcp/aerogear-data-sync-server/node_modules/graphql/language/parser.js:757:16) |
at parseTypeSystemDefinition (/Users/dara/mcp/aerogear-data-sync-server/node_modules/graphql/language/parser.js:663:16) |
at parseDefinition (/Users/dara/mcp/aerogear-data-sync-server/node_modules/graphql/language/parser.js:143:16) |
at parseDocument (/Users/dara/mcp/aerogear-data-sync-server/node_modules/graphql/language/parser.js:110:22) |
at parse (/Users/dara/mcp/aerogear-data-sync-server/node_modules/graphql/language/parser.js:38:10)
|
|