mirror of
https://github.com/wassname/talk.git
synced 2026-07-09 23:12:09 +08:00
improved introspection
This commit is contained in:
+1
-1
@@ -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": [
|
||||
".",
|
||||
|
||||
+2
-1
@@ -2,4 +2,5 @@ public/*
|
||||
!public/_redirects
|
||||
.deploy*/
|
||||
db.json
|
||||
*.log
|
||||
*.log
|
||||
source/_data/introspection.json
|
||||
@@ -12,4 +12,4 @@ interact with Talk's GraphQL endpoint.
|
||||
|
||||
# GraphQL Schema
|
||||
|
||||
{% graphqldocs ../../client/coral-framework/graphql/introspection.json %}
|
||||
{% graphqldocs _data/introspection.json %}
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user