Skip to content

Commit 27b8560

Browse files
committed
refactor: due changes in [email protected]
BREAKING CHANGE: Using API from [email protected]
1 parent 041e4ef commit 27b8560

File tree

7 files changed

+2007
-1879
lines changed

7 files changed

+2007
-1879
lines changed

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"prettier.eslintIntegration": true,
3+
"eslint.validate": [
4+
"javascript",
5+
],
6+
"javascript.validate.enable": false
7+
}

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
[![travis build](https://img.shields.io/travis/graphql-compose/graphql-compose-json.svg)](https://travis-ci.org/graphql-compose/graphql-compose-json)
44
[![codecov coverage](https://img.shields.io/codecov/c/github/graphql-compose/graphql-compose-json.svg)](https://codecov.io/github/graphql-compose/graphql-compose-json)
5-
[![](https://img.shields.io/npm/v/graphql-compose-json.svg)](https://www.npmjs.com/package/graphql-compose-json)
6-
[![npm](https://img.shields.io/npm/dt/graphql-compose-json.svg)](http://www.npmtrends.com/graphql-compose-json)
5+
[![npm](https://img.shields.io/npm/v/graphql-compose-json.svg)](https://www.npmjs.com/package/graphql-compose-json)
6+
[![trends](https://img.shields.io/npm/dt/graphql-compose-json.svg)](http://www.npmtrends.com/graphql-compose-json)
77
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
88
[![Greenkeeper badge](https://badges.greenkeeper.io/graphql-compose/graphql-compose-json.svg)](https://greenkeeper.io/)
99

@@ -78,7 +78,9 @@ const restApiResponse = {
7878
export const CustomPersonTC = composeWithJson('CustomPerson', restApiResponse);
7979
export const CustomPersonGraphQLType = CustomPersonTC.getType();
8080
```
81+
8182
Will be produced following GraphQL Type from upper shape:
83+
8284
```js
8385
const CustomPersonGraphQLType = new GraphQLObjectType({
8486
name: 'CustomPerson',
@@ -135,9 +137,9 @@ const schema = new GraphQLSchema({
135137
Or do the same via `graphql-compose`:
136138

137139
```js
138-
import { GQC } from 'graphql-compose';
140+
import { schemaComposer } from 'graphql-compose';
139141

140-
GQC.rootQuery().addFields({
142+
schemaComposer.Query.addFields({
141143
person: {
142144
type: PersonTC,
143145
args: {
@@ -148,12 +150,13 @@ GQC.rootQuery().addFields({
148150
},
149151
}
150152

151-
const schema = GQC.buildSchema(); // returns GraphQLSchema
153+
const schema = schemaComposer.buildSchema(); // returns GraphQLSchema
152154
```
153155
154156
## Building schema asynchronously
155157
156158
To build the schema at the runtime, you should rewrite the `Schema.js` and insert there an async function which will return a promise:
159+
157160
```js
158161
export const buildAsyncSchema = async (): Promise<GraphQLSchema> => {
159162
const url = `https://swapi.co/api/people/1`;
@@ -172,11 +175,11 @@ export const buildAsyncSchema = async (): Promise<GraphQLSchema> => {
172175
},
173176
});
174177

175-
GQC.rootQuery().addFields({
178+
schemaComposer.Query.addFields({
176179
person: PeopleTC.getResolver('findById'),
177180
});
178181

179-
const schema = GQC.buildSchema();
182+
const schema = schemaComposer.buildSchema();
180183
return schema;
181184
};
182185
```
@@ -202,8 +205,6 @@ app.use(
202205
);
203206
```
204207
205-
206-
207208
## Further customization with `graphql-compose`
208209
209210
Moreover, `graphql-compose` allows you to pass pre-defined resolvers of other types to the response object and customize them:

package.json

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,37 @@
2323
},
2424
"homepage": "https://github.com/graphql-compose/graphql-compose-json",
2525
"peerDependencies": {
26-
"graphql-compose": ">=5.0.1 || >=4.0.0 || >=3.0.0 || >=2.9.5"
26+
"graphql-compose": ">=6.0.0"
2727
},
2828
"devDependencies": {
29-
"@babel/cli": "^7.0.0",
30-
"@babel/core": "^7.0.0",
31-
"@babel/node": "^7.0.0",
32-
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
33-
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
34-
"@babel/plugin-transform-runtime": "^7.0.0",
35-
"@babel/preset-env": "^7.0.0",
29+
"@babel/cli": "^7.2.3",
30+
"@babel/core": "^7.3.4",
31+
"@babel/node": "^7.2.2",
32+
"@babel/plugin-proposal-object-rest-spread": "^7.3.4",
33+
"@babel/plugin-transform-flow-strip-types": "^7.3.4",
34+
"@babel/plugin-transform-runtime": "^7.3.4",
35+
"@babel/preset-env": "^7.3.4",
3636
"@babel/preset-flow": "^7.0.0",
3737
"babel-core": "^7.0.0-bridge.0",
38-
"babel-eslint": "^9.0.0",
39-
"babel-jest": "^23.4.2",
38+
"babel-eslint": "^10.0.1",
39+
"babel-jest": "^24.5.0",
4040
"cz-conventional-changelog": "^2.1.0",
41-
"eslint": "^5.5.0",
41+
"eslint": "^5.15.2",
4242
"eslint-config-airbnb-base": "^13.1.0",
43-
"eslint-config-prettier": "^3.0.1",
44-
"eslint-plugin-flowtype": "^2.50.0",
45-
"eslint-plugin-import": "^2.14.0",
46-
"eslint-plugin-prettier": "^2.6.2",
47-
"express": "^4.16.3",
48-
"express-graphql": "^0.6.12",
49-
"flow-bin": "^0.80.0",
50-
"graphql": "14.0.0",
51-
"graphql-compose": "^5.0.1",
52-
"jest": "^23.5.0",
53-
"node-fetch": "^2.2.0",
54-
"prettier": "^1.14.2",
55-
"rimraf": "^2.6.2",
56-
"semantic-release": "^15.9.12"
43+
"eslint-config-prettier": "^4.1.0",
44+
"eslint-plugin-flowtype": "^3.4.2",
45+
"eslint-plugin-import": "^2.16.0",
46+
"eslint-plugin-prettier": "^3.0.1",
47+
"express": "^4.16.4",
48+
"express-graphql": "^0.7.1",
49+
"flow-bin": "^0.95.1",
50+
"graphql": "14.1.1",
51+
"graphql-compose": "^6.0.1",
52+
"jest": "^24.5.0",
53+
"node-fetch": "^2.3.0",
54+
"prettier": "^1.16.4",
55+
"rimraf": "^2.6.3",
56+
"semantic-release": "^15.13.3"
5757
},
5858
"config": {
5959
"commitizen": {

src/ObjectParser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/* @flow */
22

3-
import { TypeComposer, upperFirst, type ComposeFieldConfig } from 'graphql-compose';
3+
import { ObjectTypeComposer, upperFirst, type ComposeFieldConfig } from 'graphql-compose';
44

55
type GetValueOpts = {
66
typeName: string,
77
fieldName: string,
88
};
99

1010
export default class ObjectParser {
11-
static createTC(name: string, json: Object): TypeComposer {
11+
static createTC(name: string, json: Object): ObjectTypeComposer<any, any> {
1212
if (!json || typeof json !== 'object') {
1313
throw new Error('You provide empty object in second arg for `createTC` method.');
1414
}
15-
const tc = TypeComposer.create(name);
15+
const tc = ObjectTypeComposer.createTemp(name);
1616

1717
const fields = {};
1818
Object.keys(json).forEach(k => {

src/__fixtures__/Schema.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/* @flow */
22

3-
import { GQC } from 'graphql-compose';
3+
import { schemaComposer } from 'graphql-compose';
44
import { FilmTC } from './Film';
55
import { PeopleTC } from './People';
66

7-
GQC.rootQuery().addFields({
7+
schemaComposer.Query.addFields({
88
film: FilmTC.getResolver('findById'),
99
people: PeopleTC.getResolver('findById'),
1010
peopleByUrl: PeopleTC.getResolver('findByUrl'),
1111
peopleByUrls: PeopleTC.getResolver('findByUrlList'),
1212
});
1313

14-
const schema = GQC.buildSchema();
14+
const schema = schemaComposer.buildSchema();
1515

1616
export default schema;

src/__tests__/ObjectParser-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
import { graphql, TypeComposer } from 'graphql-compose';
3+
import { graphql, ObjectTypeComposer } from 'graphql-compose';
44
import OP from '../ObjectParser';
55

66
const { GraphQLFloat, GraphQLBoolean } = graphql;
@@ -61,9 +61,9 @@ describe('ObjectParser', () => {
6161
});
6262

6363
describe('createTC()', () => {
64-
it('return TypeComposer', () => {
64+
it('return ObjectTypeComposer', () => {
6565
const tc = OP.createTC('MyType', { a: 1 });
66-
expect(tc).toBeInstanceOf(TypeComposer);
66+
expect(tc).toBeInstanceOf(ObjectTypeComposer);
6767
expect(tc.getTypeName()).toBe('MyType');
6868
});
6969

0 commit comments

Comments
 (0)