diff --git a/package.json b/package.json index e69b913..ad75818 100644 --- a/package.json +++ b/package.json @@ -1,66 +1,71 @@ { - "name": "graphql-docs", - "version": "0.2.0", - "description": "Dynamic documentation for GraphQL endpoints", - "main": "dist/graphql-docs.js", - "author": "Magnus Hallin ", - "license": "SEE LICENSE IN LICENSE", - "files": [ - "dist/", - "lib/", - "README.rst", - "LICENSE" - ], - "bin": { - "graphql-docs-gen": "lib/generator.js" - }, - "scripts": { - "test": "echo 'No tests yet :-('", - "lint": "./node_modules/.bin/eslint src", - "flow": "./node_modules/.bin/flow check", - "prepublish": "./scripts/build.sh" - }, - "keywords": ["graphql", "react", "docs", "documentation"], - "homepage": "https://github.com/mhallin/graphql-docs", - "repository": { - "type": "git", - "url": "https://github.com/mhallin/graphql-docs.git" - }, - "bugs": { - "url": "https://github.com/mhallin/graphql-docs/issues" - }, - "engines": { - "node": ">= 4.4.0" - }, - "peerDependencies": { - "react": "^15.0.1", - "react-dom": "^15.0.1" - }, - "dependencies": { - "marked": "^0.3.5", - "request": "^2.74.0", - "yargs": "^5.0.0" - }, - "devDependencies": { - "babel-core": "^6.7.7", - "babel-cli": "^6.7.7", - "babel-eslint": "^6.0.4", - "babel-loader": "^6.2.4", - "babel-plugin-contracts": "^1.1.1", - "babel-plugin-transform-flow-strip-types": "^6.7.0", - "babel-preset-es2015": "^6.6.0", - "babel-preset-react": "^6.5.0", - "babel-preset-stage-0": "^6.5.0", - "css-loader": "^0.25.0", - "eslint": "^3.5.0", - "eslint-plugin-flowtype": "^2.4.0", - "eslint-plugin-react": "^6.2.2", - "expose-loader": "^0.7.1", - "flow-bin": "^0.32.0", - "postcss-cssnext": "^2.5.2", - "postcss-loader": "^0.13.0", - "raw-loader": "^0.5.1", - "style-loader": "^0.13.1", - "webpack": "^1.13.0" - } -} + "name": "graphql-docs", + "version": "0.2.1", + "description": "Dynamic documentation for GraphQL endpoints", + "main": "dist/graphql-docs.js", + "author": "Magnus Hallin ", + "license": "SEE LICENSE IN LICENSE", + "files": [ + "dist/", + "lib/", + "README.rst", + "LICENSE" + ], + "bin": { + "graphql-docs-gen": "lib/generator.js" + }, + "scripts": { + "test": "echo 'No tests yet :-('", + "lint": "./node_modules/.bin/eslint src", + "flow": "./node_modules/.bin/flow check", + "prepublish": "./scripts/build.sh" + }, + "keywords": [ + "graphql", + "react", + "docs", + "documentation" + ], + "homepage": "https://github.com/mhallin/graphql-docs", + "repository": { + "type": "git", + "url": "https://github.com/mhallin/graphql-docs.git" + }, + "bugs": { + "url": "https://github.com/mhallin/graphql-docs/issues" + }, + "engines": { + "node": ">= 4.4.0" + }, + "peerDependencies": { + "react": "^15.0.1", + "react-dom": "^15.0.1" + }, + "dependencies": { + "marked": "^0.3.5", + "request": "^2.74.0", + "yargs": "^5.0.0" + }, + "devDependencies": { + "babel-core": "^6.7.7", + "babel-cli": "^6.7.7", + "babel-eslint": "^6.0.4", + "babel-loader": "^6.2.4", + "babel-plugin-contracts": "^1.1.1", + "babel-plugin-transform-flow-strip-types": "^6.7.0", + "babel-preset-es2015": "^6.6.0", + "babel-preset-react": "^6.5.0", + "babel-preset-stage-0": "^6.5.0", + "css-loader": "^0.25.0", + "eslint": "^3.5.0", + "eslint-plugin-flowtype": "^2.4.0", + "eslint-plugin-react": "^6.2.2", + "expose-loader": "^0.7.1", + "flow-bin": "^0.32.0", + "postcss-cssnext": "^2.5.2", + "postcss-loader": "^0.13.0", + "raw-loader": "^0.5.1", + "style-loader": "^0.13.1", + "webpack": "^1.13.0" + } +} \ No newline at end of file diff --git a/src/components/SchemaDocsView.js b/src/components/SchemaDocsView.js index e7e0462..f31f588 100644 --- a/src/components/SchemaDocsView.js +++ b/src/components/SchemaDocsView.js @@ -2,10 +2,10 @@ import React from 'react'; -import { Schema, Type, ObjectType, InterfaceType, EnumType, ScalarType, InputObjectType } from '../model'; +import { Schema, Type, ObjectType, InterfaceType, EnumType, ScalarType, InputObjectType, UnionType } from '../model'; import { getReferencesInSchema } from '../schemaWalker'; -import { ObjectDocsView, InterfaceDocsView, EnumDocsView, ScalarDocsView, InputObjectDocsView } from './TypeDocsViews'; +import { ObjectDocsView, InterfaceDocsView, EnumDocsView, ScalarDocsView, InputObjectDocsView, UnionDocsView } from './TypeDocsViews'; import * as StyleSheet from './SchemaDocsView.css'; @@ -27,6 +27,13 @@ export class SchemaDocsView extends React.Component { titleOverride={this.titleOverrideFor(t)} />); } + if (t instanceof UnionType) { + components.push( + ); + } if (t instanceof InterfaceType) { components.push( + {renderTitle(type.name)} + {renderDescription(type.description)} + {renderPossibleTypes(type.possibleTypes)} + + ); + } +} export class InputObjectDocsView extends React.Component { props: { @@ -179,7 +195,26 @@ function renderImplementors(possibleTypes: Array) { ); } +function renderPossibleTypes(possibleTypes: Array) { + if (!possibleTypes.length) { + return null; + } + + return ( +
+
+ Possible Types +
+
    + {possibleTypes.map((r, i) => +
  • + +
  • )} +
+
+ ); +} function renderEnumValues(enumValues: Array) { if (!enumValues.length) { return null; diff --git a/src/introspectionQuery.txt b/src/introspectionQuery.txt index e61df51..1435169 100644 --- a/src/introspectionQuery.txt +++ b/src/introspectionQuery.txt @@ -1,86 +1,93 @@ -query IntrospectionQuery { - __schema { - queryType { - name - } - mutationType { - name - } - subscriptionType { - name - } - types { - ...FullType + + query IntrospectionQuery { + __schema { + queryType { name } + mutationType { name } + subscriptionType { name } + types { + ...FullType + } + directives { + name + description + locations + args { + ...InputValue + } + } + } } - directives { + + fragment FullType on __Type { + kind + name + description + fields(includeDeprecated: true) { name description args { ...InputValue } - onOperation - onFragment - onField + type { + ...TypeRef + } + isDeprecated + deprecationReason } - } -} - -fragment FullType on __Type { - kind - name - description - fields(includeDeprecated: true) { - name - description - args { + inputFields { ...InputValue } - type { + interfaces { + ...TypeRef + } + enumValues(includeDeprecated: true) { + name + description + isDeprecated + deprecationReason + } + possibleTypes { ...TypeRef } - isDeprecated - deprecationReason - } - inputFields { - ...InputValue - } - interfaces { - ...TypeRef } - enumValues(includeDeprecated: true) { + + fragment InputValue on __InputValue { name description - isDeprecated - deprecationReason - } - possibleTypes { - ...TypeRef - } -} - -fragment InputValue on __InputValue { - name - description - type { - ...TypeRef + type { ...TypeRef } + defaultValue } - defaultValue -} -fragment TypeRef on __Type { - kind - name - ofType { - kind - name - ofType { + 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 + } + } + } + } + } + } } } - } -} - + \ No newline at end of file diff --git a/src/model.js b/src/model.js index 055fa65..8975def 100644 --- a/src/model.js +++ b/src/model.js @@ -6,6 +6,7 @@ export const TYPE_KINDS = [ 'OBJECT', 'ENUM', 'INPUT_OBJECT', + 'UNION', ]; export type TypeId = string; @@ -79,6 +80,8 @@ export class Type { return new EnumType(introspectionType); } else if (introspectionType.kind === 'INPUT_OBJECT') { return new InputObjectType(introspectionType); + } else if (introspectionType.kind === 'UNION') { + return new UnionType(introspectionType); } else { throw new Error('Unsupported type kind: ' + introspectionType.kind); } @@ -129,6 +132,20 @@ export class ScalarType extends Type { } } +export class UnionType extends Type { + possibleTypes: Array; + constructor(introspectionType: any) { + pre: { + introspectionType.kind === 'UNION'; + Array.isArray(introspectionType.possibleTypes); + } + + super(introspectionType); + this.possibleTypes = introspectionType.possibleTypes.map(r => TypeRef.fromIntrospectionRef(r)); + } + +} + export class InterfaceType extends Type { fields: Array; possibleTypes: Array; diff --git a/src/schemaWalker.js b/src/schemaWalker.js index e1f73fe..d05049c 100644 --- a/src/schemaWalker.js +++ b/src/schemaWalker.js @@ -1,6 +1,6 @@ // @flow -import { Type, Schema, ObjectType, InterfaceType, InputObjectType, Field, TypeRef, NonNullTypeRef, NamedTypeRef, ListTypeRef } from './model'; +import { Type, Schema, ObjectType, InterfaceType, InputObjectType, Field, TypeRef, NonNullTypeRef, NamedTypeRef, ListTypeRef, UnionType } from './model'; import type { TypeId } from './model'; @@ -56,6 +56,10 @@ function getReferencesInType(type: Type): Bag { type.inputFields.forEach(iv => addTypeRefToBag(iv.type, refs)); } + if (type instanceof UnionType) { + type.possibleTypes.forEach(r => addTypeRefToBag(r, refs)); + } + return refs; }