diff --git a/.nodemon.json b/.nodemon.json index 101104f4a..5e192d80c 100644 --- a/.nodemon.json +++ b/.nodemon.json @@ -1,6 +1,6 @@ { "exec": "npm-run-all --parallel generate-introspection start:development", - "ignore": ["test/*", "client/*", "dist/*", "plugins/*/client"], + "ignore": ["test/*", "client/*", "dist/*", "plugins/*/client", "docs/*"], "ext": "js,json,graphql,yml", "watch": [ ".", diff --git a/docs/.gitignore b/docs/.gitignore index b9fd845b9..be0603043 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -2,4 +2,5 @@ public/* !public/_redirects .deploy*/ db.json -*.log \ No newline at end of file +*.log +source/_data/introspection.json \ No newline at end of file diff --git a/docs/source/api/graphql.md b/docs/source/api/graphql.md index 792f2b240..4275fe7f0 100644 --- a/docs/source/api/graphql.md +++ b/docs/source/api/graphql.md @@ -12,4 +12,4 @@ interact with Talk's GraphQL endpoint. # GraphQL Schema -{% graphqldocs ../../client/coral-framework/graphql/introspection.json %} \ No newline at end of file +{% graphqldocs _data/introspection.json %} \ No newline at end of file diff --git a/scripts/generateIntrospectionResult.js b/scripts/generateIntrospectionResult.js index e07fe7c6d..7c3ea024c 100755 --- a/scripts/generateIntrospectionResult.js +++ b/scripts/generateIntrospectionResult.js @@ -1,7 +1,120 @@ #! /usr/bin/env node const path = require('path'); -const introspectionFilename = path.resolve( +const fs = require('fs'); +const { graphql } = require('graphql'); +const schema = require('../graph/schema'); + +// Copied from https://github.com/graphql/graphql-js/blob/f995c1f92e94d9c451104b6a0db8034165ef8640/src/utilities/introspectionQuery.js#L18-L113 +// which is available in graphql@0.13.2 +// +// TODO: remove when we upgrade to at least graphql@0.13.2. +function getIntrospectionQuery(options = {}) { + const descriptions = !(options && options.descriptions === false); + return ` + query IntrospectionQuery { + __schema { + queryType { name } + mutationType { name } + subscriptionType { name } + types { + ...FullType + } + directives { + name + ${descriptions ? 'description' : ''} + locations + args { + ...InputValue + } + } + } + } + fragment FullType on __Type { + kind + name + ${descriptions ? 'description' : ''} + fields(includeDeprecated: true) { + name + ${descriptions ? 'description' : ''} + args { + ...InputValue + } + type { + ...TypeRef + } + isDeprecated + deprecationReason + } + inputFields { + ...InputValue + } + interfaces { + ...TypeRef + } + enumValues(includeDeprecated: true) { + name + ${descriptions ? 'description' : ''} + isDeprecated + deprecationReason + } + possibleTypes { + ...TypeRef + } + } + fragment InputValue on __InputValue { + name + ${descriptions ? 'description' : ''} + type { ...TypeRef } + defaultValue + } + fragment TypeRef on __Type { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + } + } + } + } + } + } + } + } + `; +} + +const generateIntrospectionResult = (resultLocation, options = {}) => + graphql(schema, getIntrospectionQuery(options)).then(({ data }) => { + // Serialize the introspection result as JSON. + const introspectionResult = JSON.stringify(data, null, 2); + + // Write the introspection result to the filesystem. + fs.writeFileSync(resultLocation, introspectionResult, 'utf8'); + + console.log(`Outputted result of introspectionQuery to ${resultLocation}`); + }); + +const graphIntrospectionFilename = path.resolve( __dirname, '..', 'client', @@ -10,23 +123,21 @@ const introspectionFilename = path.resolve( 'introspection.json' ); -const fs = require('fs'); -const { graphql, introspectionQuery } = require('graphql'); -const schema = require('../graph/schema'); +const docsIntrospectionFilename = path.resolve( + __dirname, + '..', + 'docs', + 'source', + '_data', + 'introspection.json' +); -graphql(schema, introspectionQuery) - .then(({ data }) => { - // Serialize the introspection result as JSON. - const introspectionResult = JSON.stringify(data, null, 2); - - // Write the introspection result to the filesystem. - fs.writeFileSync(introspectionFilename, introspectionResult, 'utf8'); - - console.log( - `Outputted result of introspectionQuery to ${introspectionFilename}` - ); - }) - .catch(err => { - console.error(err); - process.exit(1); - }); +Promise.all([ + generateIntrospectionResult(graphIntrospectionFilename, { + descriptions: false, + }), + generateIntrospectionResult(docsIntrospectionFilename), +]).catch(err => { + console.error(err); + process.exit(1); +});