Skip to content

Commit 99edddb

Browse files
committed
feat: allow to pass SchemaComposer's type instances without wrapping them in functions
1 parent 6952f5a commit 99edddb

File tree

6 files changed

+107
-79
lines changed

6 files changed

+107
-79
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,30 @@
2828
"@types/express": "4.17.4",
2929
"@types/express-graphql": "^0.9.0",
3030
"@types/graphql": "^14.5.0",
31-
"@types/jest": "25.2.1",
32-
"@types/node": "13.13.5",
31+
"@types/jest": "25.2.2",
32+
"@types/node": "14.0.1",
3333
"@types/node-fetch": "2.5.7",
34-
"@typescript-eslint/eslint-plugin": "2.31.0",
35-
"@typescript-eslint/parser": "2.31.0",
34+
"@typescript-eslint/eslint-plugin": "2.34.0",
35+
"@typescript-eslint/parser": "2.34.0",
3636
"cross-env": "7.0.2",
3737
"eslint": "7.0.0",
3838
"eslint-config-airbnb-base": "14.1.0",
3939
"eslint-config-prettier": "6.11.0",
40-
"eslint-plugin-flowtype": "4.7.0",
40+
"eslint-plugin-flowtype": "5.1.0",
4141
"eslint-plugin-import": "2.20.2",
4242
"eslint-plugin-prettier": "3.1.3",
4343
"express": "^4.17.1",
4444
"express-graphql": "^0.9.0",
4545
"graphql": "15.0.0",
46-
"graphql-compose": "7.14.4",
46+
"graphql-compose": "7.15.0",
4747
"jest": "26.0.1",
4848
"node-fetch": "^2.6.0",
4949
"prettier": "2.0.5",
5050
"rimraf": "3.0.2",
5151
"semantic-release": "17.0.7",
52-
"ts-jest": "25.5.1",
52+
"ts-jest": "26.0.0",
5353
"ts-node": "8.10.1",
54-
"typescript": "^3.8.3"
54+
"typescript": "3.9.2"
5555
},
5656
"scripts": {
5757
"build": "rimraf lib && tsc -p ./tsconfig.build.json",

src/InputObjectParser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
InputTypeComposerFieldConfigDefinition,
55
schemaComposer,
66
SchemaComposer,
7+
isComposeInputType,
78
} from 'graphql-compose';
89

910
type GetValueOpts = {
@@ -42,6 +43,10 @@ export default class InputObjectParser {
4243
if (typeOf === 'string') return 'String';
4344
if (typeOf === 'boolean') return 'Boolean';
4445

46+
if (isComposeInputType(value)) {
47+
return value;
48+
}
49+
4550
if (typeOf === 'object') {
4651
if (value === null) return 'JSON';
4752

src/ObjectParser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ObjectTypeComposerFieldConfigDefinition,
55
schemaComposer,
66
SchemaComposer,
7+
isComposeOutputType,
78
} from 'graphql-compose';
89

910
type GetValueOpts = {
@@ -42,6 +43,10 @@ export default class ObjectParser {
4243
if (typeOf === 'string') return 'String';
4344
if (typeOf === 'boolean') return 'Boolean';
4445

46+
if (isComposeOutputType(value)) {
47+
return value;
48+
}
49+
4550
if (typeOf === 'object') {
4651
if (value === null) return 'JSON';
4752

src/__tests__/InputObjectParser-test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InputTypeComposer } from 'graphql-compose';
1+
import { InputTypeComposer, schemaComposer } from 'graphql-compose';
22
import IOP from '../InputObjectParser';
33

44
describe('InputObjectParser', () => {
@@ -87,7 +87,7 @@ describe('InputObjectParser', () => {
8787
mass: () => 'Int',
8888
hair_color: 'blond',
8989
skin_color: 'fair',
90-
eye_color: 'blue',
90+
eye_color: schemaComposer.createEnumTC(`enum EyeColor { blue brown }`),
9191
birth_year: '19BBY',
9292
gender: 'male',
9393
homeworld: {
@@ -105,6 +105,7 @@ describe('InputObjectParser', () => {
105105
],
106106
created: () => 'Date',
107107
edited: '2014-12-20T21:17:56.891000Z',
108+
filter: schemaComposer.createInputTC(`input FilterInput { name: String, mass: Int }`),
108109
});
109110

110111
expect(PeopleITC.toSDL({ deep: true, omitScalars: true })).toMatchInlineSnapshot(`
@@ -114,13 +115,19 @@ describe('InputObjectParser', () => {
114115
mass: Int
115116
hair_color: String
116117
skin_color: String
117-
eye_color: String
118+
eye_color: EyeColor
118119
birth_year: String
119120
gender: String
120121
homeworld: PeopleInput_Homeworld
121122
films: [String]
122123
created: Date
123124
edited: String
125+
filter: FilterInput
126+
}
127+
128+
enum EyeColor {
129+
blue
130+
brown
124131
}
125132
126133
input PeopleInput_Homeworld {
@@ -130,6 +137,11 @@ describe('InputObjectParser', () => {
130137
terrain: String
131138
surface_water: String
132139
population: Int
140+
}
141+
142+
input FilterInput {
143+
name: String
144+
mass: Int
133145
}"
134146
`);
135147
});

src/__tests__/ObjectParser-test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ObjectTypeComposer } from 'graphql-compose';
1+
import { ObjectTypeComposer, schemaComposer } from 'graphql-compose';
22
import OP from '../ObjectParser';
33

44
describe('ObjectParser', () => {
@@ -105,6 +105,7 @@ describe('ObjectParser', () => {
105105
],
106106
created: () => 'Date',
107107
edited: '2014-12-20T21:17:56.891000Z',
108+
meta: schemaComposer.createObjectTC('type Meta { key: String, val: String }').List,
108109
});
109110

110111
expect(PeopleTC.toSDL({ deep: true, omitScalars: true })).toMatchInlineSnapshot(`
@@ -121,6 +122,7 @@ describe('ObjectParser', () => {
121122
films: [String]
122123
created: Date
123124
edited: String
125+
meta: [Meta]
124126
}
125127
126128
type PeopleType_Homeworld {
@@ -130,6 +132,11 @@ describe('ObjectParser', () => {
130132
terrain: String
131133
surface_water: String
132134
population: Int
135+
}
136+
137+
type Meta {
138+
key: String
139+
val: String
133140
}"
134141
`);
135142
});

0 commit comments

Comments
 (0)