From a6890fdef545ebd4d8fb359e0d6ff54a5ac88f70 Mon Sep 17 00:00:00 2001 From: Rikki Schulte Date: Tue, 2 Apr 2019 07:18:34 -0400 Subject: [PATCH 1/2] update tests, example with inputUnion --- example/schema.js | 94 ++++++++++++++++--------- src/components/DocExplorer/TypeDoc.js | 98 ++++++++++++++------------- test/schema.js | 53 +++++++++++++++ 3 files changed, 166 insertions(+), 79 deletions(-) diff --git a/example/schema.js b/example/schema.js index 850249a8eb0..c9821d160cb 100644 --- a/example/schema.js +++ b/example/schema.js @@ -9,6 +9,7 @@ const { GraphQLSchema, GraphQLObjectType, GraphQLUnionType, + GraphQLInputUnionType, GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, @@ -26,8 +27,8 @@ const TestEnum = new GraphQLEnumType({ values: { RED: { description: 'A rosy color' }, GREEN: { description: 'The color of martians and slime' }, - BLUE: { description: 'A feeling you might have if you can\'t use GraphQL' }, - } + BLUE: { description: "A feeling you might have if you can't use GraphQL" }, + }, }); const TestInputObject = new GraphQLInputObjectType({ @@ -35,7 +36,7 @@ const TestInputObject = new GraphQLInputObjectType({ fields: () => ({ string: { type: GraphQLString, - description: 'Repeats back this string' + description: 'Repeats back this string', }, int: { type: GraphQLInt }, float: { type: GraphQLFloat }, @@ -51,7 +52,7 @@ const TestInputObject = new GraphQLInputObjectType({ listID: { type: new GraphQLList(GraphQLID) }, listEnum: { type: new GraphQLList(TestEnum) }, listObject: { type: new GraphQLList(TestInputObject) }, - }) + }), }); const TestInterface = new GraphQLInterfaceType({ @@ -60,12 +61,12 @@ const TestInterface = new GraphQLInterfaceType({ fields: () => ({ name: { type: GraphQLString, - description: 'Common name string.' - } + description: 'Common name string.', + }, }), resolveType: check => { return check ? UnionFirst : UnionSecond; - } + }, }); const UnionFirst = new GraphQLObjectType({ @@ -73,14 +74,16 @@ const UnionFirst = new GraphQLObjectType({ fields: () => ({ name: { type: GraphQLString, - description: 'Common name string for UnionFirst.' + description: 'Common name string for UnionFirst.', }, first: { type: new GraphQLList(TestInterface), - resolve: () => { return true; } - } + resolve: () => { + return true; + }, + }, }), - interfaces: [ TestInterface ] + interfaces: [TestInterface], }); const UnionSecond = new GraphQLObjectType({ @@ -88,22 +91,49 @@ const UnionSecond = new GraphQLObjectType({ fields: () => ({ name: { type: GraphQLString, - description: 'Common name string for UnionFirst.' + description: 'Common name string for UnionFirst.', }, second: { type: TestInterface, - resolve: () => { return false; } - } + resolve: () => { + return false; + }, + }, }), - interfaces: [ TestInterface ] + interfaces: [TestInterface], }); const TestUnion = new GraphQLUnionType({ name: 'TestUnion', - types: [ UnionFirst, UnionSecond ], + types: [UnionFirst, UnionSecond], resolveType() { return UnionFirst; - } + }, +}); + +const InputUnionFirst = new GraphQLInputObjectType({ + name: 'InputUnionFirst', + fields: () => ({ + name: { + type: GraphQLString, + description: 'Common name string for InputUnionFirst.', + }, + }), +}); + +const InputUnionSecond = new GraphQLInputObjectType({ + name: 'InputUnionSecond', + fields: () => ({ + name: { + type: GraphQLString, + description: 'Common name string for InputUnionFirst.', + }, + }), +}); + +const TestInputUnion = new GraphQLInputUnionType({ + name: 'TestInputUnion', + types: [InputUnionFirst, InputUnionSecond], }); const TestType = new GraphQLObjectType({ @@ -112,12 +142,11 @@ const TestType = new GraphQLObjectType({ test: { type: TestType, description: '`test` field from `Test` type.', - resolve: () => ({}) + resolve: () => ({}), }, union: { type: TestUnion, description: '> union field from Test type, block-quoted.', - resolve: () => ({}) }, id: { type: GraphQLID, @@ -129,7 +158,7 @@ const TestType = new GraphQLObjectType({ description: 'Is this a test schema? Sure it is.', resolve: () => { return true; - } + }, }, hasArgs: { type: GraphQLString, @@ -144,6 +173,8 @@ const TestType = new GraphQLObjectType({ id: { type: GraphQLID }, enum: { type: TestEnum }, object: { type: TestInputObject }, + union: { type: TestInputUnion }, + // List listString: { type: new GraphQLList(GraphQLString) }, listInt: { type: new GraphQLList(GraphQLInt) }, @@ -152,9 +183,10 @@ const TestType = new GraphQLObjectType({ listID: { type: new GraphQLList(GraphQLID) }, listEnum: { type: new GraphQLList(TestEnum) }, listObject: { type: new GraphQLList(TestInputObject) }, - } + listUnion: { type: new GraphQLList(TestInputUnion) }, + }, }, - }) + }), }); const TestMutationType = new GraphQLObjectType({ @@ -165,10 +197,10 @@ const TestMutationType = new GraphQLObjectType({ type: GraphQLString, description: 'Set the string field', args: { - value: { type: GraphQLString } - } - } - } + value: { type: GraphQLString }, + }, + }, + }, }); const TestSubscriptionType = new GraphQLObjectType({ @@ -179,16 +211,16 @@ const TestSubscriptionType = new GraphQLObjectType({ type: TestType, description: 'Subscribe to the test type', args: { - id: { type: GraphQLString } - } - } - } + id: { type: GraphQLString }, + }, + }, + }, }); const myTestSchema = new GraphQLSchema({ query: TestType, mutation: TestMutationType, - subscription: TestSubscriptionType + subscription: TestSubscriptionType, }); module.exports = myTestSchema; diff --git a/src/components/DocExplorer/TypeDoc.js b/src/components/DocExplorer/TypeDoc.js index 2c041281225..13aaddaab98 100644 --- a/src/components/DocExplorer/TypeDoc.js +++ b/src/components/DocExplorer/TypeDoc.js @@ -12,6 +12,7 @@ import { GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, + GraphQLInputUnionType, GraphQLEnumType, } from 'graphql'; @@ -49,9 +50,13 @@ export default class TypeDoc extends React.Component { let typesTitle; let types; + if (type instanceof GraphQLUnionType) { typesTitle = 'possible types'; types = schema.getPossibleTypes(type); + } else if (type instanceof GraphQLInputUnionType) { + typesTitle = 'possible input types'; + types = schema.getPossibleTypes(type); } else if (type instanceof GraphQLInterfaceType) { typesTitle = 'implementations'; types = schema.getPossibleTypes(type); @@ -65,11 +70,11 @@ export default class TypeDoc extends React.Component { typesDef = (
{typesTitle}
- {types.map(subtype => ( + {types.map(subtype =>
-
- ))} +
, + )} ); } @@ -85,15 +90,15 @@ export default class TypeDoc extends React.Component {
{'fields'}
{fields .filter(field => !field.isDeprecated) - .map(field => ( + .map(field => - ))} + />, + )} ); @@ -102,21 +107,21 @@ export default class TypeDoc extends React.Component { deprecatedFieldsDef = (
{'deprecated fields'}
- {!this.state.showDeprecated ? ( - - ) : ( - deprecatedFields.map(field => ( - - )) - )} + {!this.state.showDeprecated + ? + : deprecatedFields.map(field => + , + )}
); } @@ -140,15 +145,15 @@ export default class TypeDoc extends React.Component { deprecatedValuesDef = (
{'deprecated values'}
- {!this.state.showDeprecated ? ( - - ) : ( - deprecatedValues.map(value => ( - - )) - )} + {!this.state.showDeprecated + ? + : deprecatedValues.map(value => + , + )}
); } @@ -182,30 +187,28 @@ function Field({ type, field, onClickType, onClickField }) { {field.name} {field.args && - field.args.length > 0 && [ - '(', - - {field.args.map(arg => ( - - ))} - , - ')', - ]} + field.args.length > 0 && [ + '(', + + {field.args.map(arg => + , + )} + , + ')', + ]} {': '} - {field.description && ( + {field.description && - )} - {field.deprecationReason && ( + />} + {field.deprecationReason && - )} + />} ); } @@ -225,12 +228,11 @@ function EnumValue({ value }) { className="doc-value-description" markdown={value.description} /> - {value.deprecationReason && ( + {value.deprecationReason && - )} + />} ); } diff --git a/test/schema.js b/test/schema.js index a98e28b85d2..069468b1b9c 100644 --- a/test/schema.js +++ b/test/schema.js @@ -9,6 +9,7 @@ const { GraphQLSchema, GraphQLObjectType, GraphQLUnionType, + GraphQLInputUnionType, GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, @@ -128,6 +129,48 @@ const TestUnion = new GraphQLUnionType({ }, }); +const InputUnionFirst = new GraphQLObjectType({ + name: 'First', + fields: () => ({ + name: { + type: GraphQLString, + description: 'Common name string for InputUnionFirst.', + }, + first: { + type: new GraphQLList(TestInterface), + resolve: () => { + return true; + }, + }, + }), + interfaces: [TestInterface], +}); + +const InputUnionSecond = new GraphQLObjectType({ + name: 'First', + fields: () => ({ + name: { + type: GraphQLString, + description: 'Common name string for InputUnionSecond.', + }, + first: { + type: new GraphQLList(TestInterface), + resolve: () => { + return true; + }, + }, + }), + interfaces: [TestInterface], +}); + +const TestInputUnion = new GraphQLInputUnionType({ + name: 'TestInputUnion', + types: [InputUnionFirst, InputUnionSecond], + resolveType() { + return InputUnionFirst; + }, +}); + const TestType = new GraphQLObjectType({ name: 'Test', fields: () => ({ @@ -148,6 +191,16 @@ const TestType = new GraphQLObjectType({ description: '> union field from Test type, block-quoted.', resolve: () => ({}), }, + inputUnion: { + type: TestInputUnion, + description: ` + input union field from Test type, with unordered list: + - how + - about + - that + `, + resolve: () => ({}), + }, id: { type: GraphQLID, description: 'id field from Test type.', From aa29a10b3b41bc5c25aeb3b9c00addf9909b01b7 Mon Sep 17 00:00:00 2001 From: Rikki Schulte Date: Tue, 21 May 2019 05:24:14 -0400 Subject: [PATCH 2/2] temporarily remove browserify-shim for linked builds --- resources/build.sh | 4 ++-- test/server.js | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/resources/build.sh b/resources/build.sh index 770dea37ec4..68b0279ac07 100644 --- a/resources/build.sh +++ b/resources/build.sh @@ -11,9 +11,9 @@ fi rm -rf dist/ && mkdir -p dist/ babel src --ignore __tests__ --out-dir dist/ echo "Bundling graphiql.js..." -browserify -g browserify-shim -s GraphiQL dist/index.js > graphiql.js +browserify -s GraphiQL dist/index.js > graphiql.js echo "Bundling graphiql.min.js..." -browserify -g browserify-shim -t uglifyify -s GraphiQL dist/index.js 2> /dev/null | uglifyjs -c > graphiql.min.js 2> /dev/null +browserify -t uglifyify -s GraphiQL dist/index.js 2> /dev/null | uglifyjs -c > graphiql.min.js 2> /dev/null echo "Bundling graphiql.css..." postcss --no-map --use autoprefixer -d dist/ css/*.css cat dist/*.css > graphiql.css diff --git a/test/server.js b/test/server.js index ffecd8fc113..d126a39a103 100644 --- a/test/server.js +++ b/test/server.js @@ -9,7 +9,6 @@ import express from 'express'; import path from 'path'; import browserify from 'browserify'; -import browserifyShim from 'browserify-shim'; import watchify from 'watchify'; import babelify from 'babelify'; import graphqlHTTP from 'express-graphql'; @@ -28,7 +27,7 @@ const b = browserify({ entries: [path.join(__dirname, '../src/index.js')], cache: {}, packageCache: {}, - transform: [babelify, browserifyShim], + transform: [babelify], plugin: [watchify], standalone: 'GraphiQL', globalTransform: 'browserify-shim',