Skip to content

Commit

Permalink
feat: allow to pass SchemaComposer's type instances without wrapping …
Browse files Browse the repository at this point in the history
…them in functions
  • Loading branch information
nodkz committed May 18, 2020
1 parent 6952f5a commit 99edddb
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 79 deletions.
16 changes: 8 additions & 8 deletions package.json
Expand Up @@ -28,30 +28,30 @@
"@types/express": "4.17.4",
"@types/express-graphql": "^0.9.0",
"@types/graphql": "^14.5.0",
"@types/jest": "25.2.1",
"@types/node": "13.13.5",
"@types/jest": "25.2.2",
"@types/node": "14.0.1",
"@types/node-fetch": "2.5.7",
"@typescript-eslint/eslint-plugin": "2.31.0",
"@typescript-eslint/parser": "2.31.0",
"@typescript-eslint/eslint-plugin": "2.34.0",
"@typescript-eslint/parser": "2.34.0",
"cross-env": "7.0.2",
"eslint": "7.0.0",
"eslint-config-airbnb-base": "14.1.0",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-flowtype": "4.7.0",
"eslint-plugin-flowtype": "5.1.0",
"eslint-plugin-import": "2.20.2",
"eslint-plugin-prettier": "3.1.3",
"express": "^4.17.1",
"express-graphql": "^0.9.0",
"graphql": "15.0.0",
"graphql-compose": "7.14.4",
"graphql-compose": "7.15.0",
"jest": "26.0.1",
"node-fetch": "^2.6.0",
"prettier": "2.0.5",
"rimraf": "3.0.2",
"semantic-release": "17.0.7",
"ts-jest": "25.5.1",
"ts-jest": "26.0.0",
"ts-node": "8.10.1",
"typescript": "^3.8.3"
"typescript": "3.9.2"
},
"scripts": {
"build": "rimraf lib && tsc -p ./tsconfig.build.json",
Expand Down
5 changes: 5 additions & 0 deletions src/InputObjectParser.ts
Expand Up @@ -4,6 +4,7 @@ import {
InputTypeComposerFieldConfigDefinition,
schemaComposer,
SchemaComposer,
isComposeInputType,
} from 'graphql-compose';

type GetValueOpts = {
Expand Down Expand Up @@ -42,6 +43,10 @@ export default class InputObjectParser {
if (typeOf === 'string') return 'String';
if (typeOf === 'boolean') return 'Boolean';

if (isComposeInputType(value)) {
return value;
}

if (typeOf === 'object') {
if (value === null) return 'JSON';

Expand Down
5 changes: 5 additions & 0 deletions src/ObjectParser.ts
Expand Up @@ -4,6 +4,7 @@ import {
ObjectTypeComposerFieldConfigDefinition,
schemaComposer,
SchemaComposer,
isComposeOutputType,
} from 'graphql-compose';

type GetValueOpts = {
Expand Down Expand Up @@ -42,6 +43,10 @@ export default class ObjectParser {
if (typeOf === 'string') return 'String';
if (typeOf === 'boolean') return 'Boolean';

if (isComposeOutputType(value)) {
return value;
}

if (typeOf === 'object') {
if (value === null) return 'JSON';

Expand Down
18 changes: 15 additions & 3 deletions src/__tests__/InputObjectParser-test.ts
@@ -1,4 +1,4 @@
import { InputTypeComposer } from 'graphql-compose';
import { InputTypeComposer, schemaComposer } from 'graphql-compose';
import IOP from '../InputObjectParser';

describe('InputObjectParser', () => {
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('InputObjectParser', () => {
mass: () => 'Int',
hair_color: 'blond',
skin_color: 'fair',
eye_color: 'blue',
eye_color: schemaComposer.createEnumTC(`enum EyeColor { blue brown }`),
birth_year: '19BBY',
gender: 'male',
homeworld: {
Expand All @@ -105,6 +105,7 @@ describe('InputObjectParser', () => {
],
created: () => 'Date',
edited: '2014-12-20T21:17:56.891000Z',
filter: schemaComposer.createInputTC(`input FilterInput { name: String, mass: Int }`),
});

expect(PeopleITC.toSDL({ deep: true, omitScalars: true })).toMatchInlineSnapshot(`
Expand All @@ -114,13 +115,19 @@ describe('InputObjectParser', () => {
mass: Int
hair_color: String
skin_color: String
eye_color: String
eye_color: EyeColor
birth_year: String
gender: String
homeworld: PeopleInput_Homeworld
films: [String]
created: Date
edited: String
filter: FilterInput
}
enum EyeColor {
blue
brown
}
input PeopleInput_Homeworld {
Expand All @@ -130,6 +137,11 @@ describe('InputObjectParser', () => {
terrain: String
surface_water: String
population: Int
}
input FilterInput {
name: String
mass: Int
}"
`);
});
Expand Down
9 changes: 8 additions & 1 deletion src/__tests__/ObjectParser-test.ts
@@ -1,4 +1,4 @@
import { ObjectTypeComposer } from 'graphql-compose';
import { ObjectTypeComposer, schemaComposer } from 'graphql-compose';
import OP from '../ObjectParser';

describe('ObjectParser', () => {
Expand Down Expand Up @@ -105,6 +105,7 @@ describe('ObjectParser', () => {
],
created: () => 'Date',
edited: '2014-12-20T21:17:56.891000Z',
meta: schemaComposer.createObjectTC('type Meta { key: String, val: String }').List,
});

expect(PeopleTC.toSDL({ deep: true, omitScalars: true })).toMatchInlineSnapshot(`
Expand All @@ -121,6 +122,7 @@ describe('ObjectParser', () => {
films: [String]
created: Date
edited: String
meta: [Meta]
}
type PeopleType_Homeworld {
Expand All @@ -130,6 +132,11 @@ describe('ObjectParser', () => {
terrain: String
surface_water: String
population: Int
}
type Meta {
key: String
val: String
}"
`);
});
Expand Down

0 comments on commit 99edddb

Please sign in to comment.