Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphql compose 7 #169

Merged
merged 6 commits into from
Apr 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@babel/preset-env",
{
"targets": {
"node": 6
"node": 8
}
}
]
Expand All @@ -28,7 +28,7 @@
"@babel/preset-env",
{
"targets": {
"node": "8.0.0"
"node": 8
},
"loose": true,
"modules": false
Expand All @@ -50,7 +50,7 @@
"@babel/preset-env",
{
"targets": {
"node": "8.0.0"
"node": 8
},
"loose": true,
"modules": "commonjs"
Expand Down
10 changes: 3 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "ignore",
}],
"prettier/prettier": ["error", {
"printWidth": 100,
"singleQuote": true,
"trailingComma": "es5",
"functions": "ignore"
}],
"prettier/prettier": ["error"],
"import/prefer-default-export": 0,
"arrow-parens": 0,
"prefer-destructuring": 0,
Expand All @@ -43,6 +39,6 @@
"Class": true,
"Iterator": true,
"$Shape": true,
"$Keys": true,
"$Keys": true
}
}
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"tabWidth": 2,
"useTabs": false,
"printWidth": 100,
"trailingComma": "es5"
}
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Jest",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand", "--watch"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true
},
{
"name": "Jest Current File",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"${fileBasenameNoExtension}",
"--config",
"jest.config.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true
}
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"eslint.validate": [
"javascript",
],
"javascript.validate.enable": false
"javascript.validate.enable": false,
"javascript.autoClosingTags": false,
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ This library provides some amount of ready resolvers for fetch and update data w
The prototype of before save hook:

```js
(doc: mixed, rp: ExtendedResolveParams) => Promise<*>,
(doc: mixed, rp: ResolverResolveParams) => Promise<*>,
```

The typical implementation may be like this:
Expand Down
46 changes: 20 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,55 +31,49 @@
"object-path": "^0.11.4"
},
"optionalDependencies": {
"graphql-compose-connection": ">=5.0.0",
"graphql-compose-pagination": ">=5.0.0"
"graphql-compose-connection": ">=6.0.0",
"graphql-compose-pagination": ">=6.0.0"
},
"peerDependencies": {
"graphql-compose": ">=6.2.0",
"graphql-compose": ">=7.0.0",
"mongoose": ">=5.0.0 || >=4.4.0"
},
"devDependencies": {
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/plugin-proposal-object-rest-spread": "^7.4.3",
"@babel/plugin-transform-flow-strip-types": "^7.4.0",
"@babel/plugin-transform-runtime": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/plugin-proposal-object-rest-spread": "^7.4.4",
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/preset-flow": "^7.0.0",
"@types/graphql": "^14.2.0",
"@types/mongoose": "5.2.10",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.7.1",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-flowtype": "^3.5.1",
"eslint-plugin-import": "^2.16.0",
"eslint-config-prettier": "^4.2.0",
"eslint-plugin-flowtype": "^3.6.1",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-prettier": "^3.0.1",
"flow-bin": "^0.96.0",
"flow-bin": "^0.98.0",
"graphql": "14.2.1",
"graphql-compose": "^6.2.0",
"graphql-compose": "^7.0.0",
"graphql-compose-connection": ">=5.0.0",
"graphql-compose-pagination": ">=5.0.0",
"jest": "^24.7.1",
"mongodb-memory-server": "^4.2.2",
"mongoose": "^5.4.22",
"prettier": "^1.16.4",
"mongodb-memory-server": "^5.1.0",
"mongoose": "^5.5.4",
"prettier": "^1.17.0",
"request": "^2.88.0",
"rimraf": "^2.6.3",
"semantic-release": "^15.13.3",
"tslint": "^5.15.0",
"tslint": "^5.16.0",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^3.4.2"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
"typescript": "^3.4.5"
},
"scripts": {
"build": "npm run build-lib && npm run build-mjs && npm run build-es && npm run build-node8 && npm run build-ts",
Expand Down
11 changes: 5 additions & 6 deletions src/__tests__/composeWithMongoose-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ describe('composeWithMongoose ->', () => {
},
}).getInputTypeComposer();

expect(itc.isRequired('name')).toBe(true);
expect(itc.isRequired('gender')).toBe(true);
expect(itc.isRequired('age')).toBe(false);
expect(itc.isFieldNonNull('name')).toBe(true);
expect(itc.isFieldNonNull('gender')).toBe(true);
expect(itc.isFieldNonNull('age')).toBe(false);
});
});

Expand Down Expand Up @@ -208,9 +208,8 @@ describe('composeWithMongoose ->', () => {
},
},
});
const filterArgInFindOne: any = typeComposer.getResolver('findOne').getArg('filter');
const itc = schemaComposer.createInputTC(filterArgInFindOne.type);
expect(itc.isRequired('age')).toBe(true);
const filterArgInFindOne = typeComposer.getResolver('findOne').getArgITC('filter');
expect(filterArgInFindOne.isFieldNonNull('age')).toBe(true);
});

it('should use cached type to avoid maximum call stack size exceeded', () => {
Expand Down
14 changes: 7 additions & 7 deletions src/__tests__/composeWithMongooseDiscriminators-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('composeWithMongooseDiscriminators ->', () => {
});
const filterArgInFindOne: any = typeComposer.getResolver('findOne').getArg('filter');
const inputComposer = schemaComposer.createInputTC(filterArgInFindOne.type);
expect(inputComposer.isRequired('kind')).toBe(true);
expect(inputComposer.isFieldNonNull('kind')).toBe(true);
});

it('should proceed customizationOptions.inputType.fields.required', () => {
Expand All @@ -53,8 +53,8 @@ describe('composeWithMongooseDiscriminators ->', () => {
},
}).getInputTypeComposer();

expect(itc.isRequired('name')).toBe(true);
expect(itc.isRequired('friends')).toBe(true);
expect(itc.isFieldNonNull('name')).toBe(true);
expect(itc.isFieldNonNull('friends')).toBe(true);
});

it('should be passed down record opts to resolvers', () => {
Expand All @@ -68,8 +68,8 @@ describe('composeWithMongooseDiscriminators ->', () => {
},
},
});
const createOneRecordArgTC = typeComposer.getResolver('createOne').getArgTC('record');
expect(createOneRecordArgTC.isRequired('name')).toBe(true);
const createOneRecordArgTC = typeComposer.getResolver('createOne').getArgITC('record');
expect(createOneRecordArgTC.isFieldNonNull('name')).toBe(true);
expect(createOneRecordArgTC.hasField('friends')).toBe(false);
});

Expand All @@ -84,8 +84,8 @@ describe('composeWithMongooseDiscriminators ->', () => {
},
},
});
const createManyRecordsArgTC = typeComposer.getResolver('createMany').getArgTC('records');
expect(createManyRecordsArgTC.isRequired('name')).toBe(true);
const createManyRecordsArgTC = typeComposer.getResolver('createMany').getArgITC('records');
expect(createManyRecordsArgTC.isFieldNonNull('name')).toBe(true);
expect(createManyRecordsArgTC.hasField('friends')).toBe(false);
});
});
Expand Down
19 changes: 10 additions & 9 deletions src/__tests__/fieldConverter-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */
/* eslint-disable no-unused-expressions, no-template-curly-in-string */

import { EnumTypeComposer, schemaComposer } from 'graphql-compose';
import { EnumTypeComposer, schemaComposer, ListComposer } from 'graphql-compose';
import { UserModel } from '../__mocks__/userModel';
import {
deriveComplexType,
Expand Down Expand Up @@ -125,19 +125,20 @@ describe('fieldConverter', () => {
instance: 'ObjectID',
};
expect(convertFieldToGraphQL(mongooseField, '', schemaComposer)).toBe('MongoID');
expect(schemaComposer.get('MongoID')).toBe(GraphQLMongoID);
expect(schemaComposer.get('MongoID').getType()).toBe(GraphQLMongoID);
});

it('should use existed GraphQLMongoID in schemaComposer', () => {
schemaComposer.clear();
expect(schemaComposer.has('MongoID')).toBeFalsy();
schemaComposer.set('MongoID', ('MockGraphQLType': any));
const customType = schemaComposer.createScalarTC('MyMongoId');
schemaComposer.set('MongoID', customType);
const mongooseField = {
path: 'strFieldName',
instance: 'ObjectID',
};
expect(convertFieldToGraphQL(mongooseField, '', schemaComposer)).toBe('MongoID');
expect(schemaComposer.get('MongoID')).toBe('MockGraphQLType');
expect(schemaComposer.get('MongoID')).toBe(customType);
schemaComposer.delete('MongoID');
});
});
Expand Down Expand Up @@ -199,11 +200,11 @@ describe('fieldConverter', () => {
it('test object with field as array', () => {
const someDeepTC = embeddedToGraphQL(fields.someDeep, '', schemaComposer);
expect(someDeepTC.getTypeName()).toBe('SomeDeep');
const periodsType = (someDeepTC.getField('periods'): any).type;
expect(Array.isArray(periodsType)).toBeTruthy();
expect(periodsType[0].getTypeName()).toBe('SomeDeepPeriods');
expect(periodsType[0].hasField('from')).toBeTruthy();
expect(periodsType[0].hasField('to')).toBeTruthy();
expect(someDeepTC.getField('periods').type).toBeInstanceOf(ListComposer);
const tc = someDeepTC.getFieldOTC('periods');
expect(tc.getTypeName()).toBe('SomeDeepPeriods');
expect(tc.hasField('from')).toBeTruthy();
expect(tc.hasField('to')).toBeTruthy();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe('issue #117', () => {
surname: {
type: String,
required: true,
default: [],
},
sex: {
type: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ describe('issue #135 - Mongoose virtuals', () => {
schema,
source: 'query { findMany { id title virtualField123 } }',
});

expect(res).toEqual({
data: {
findMany: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('issue #136 - Mongoose virtuals', () => {
const CommentTC = composeWithMongoose(Comment);

CommentTC.wrapResolverAs('createManyFiltered', 'createMany', updateManyFiltered => {
const recordsTC = CommentTC.getResolver('createMany').getArgTC('records');
const recordsTC = CommentTC.getResolver('createMany').getArgITC('records');
const clonedRecordTC = recordsTC.clone('createManyFilteredInput');
clonedRecordTC.removeField('links').addFields({ hi: 'String' });
updateManyFiltered.extendArg('records', { type: clonedRecordTC.getTypePlural() });
Expand Down
4 changes: 2 additions & 2 deletions src/composeWithMongoose.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function composeWithMongoose<TSource, TContext>(
const name: string = (opts && opts.name) || m.modelName;

const sc = opts.schemaComposer || globalSchemaComposer;
sc.set('MongoID', MongoID);
sc.add(MongoID);
const tc = convertModelToGraphQL((m: any), name, sc);

if (opts.description) {
Expand Down Expand Up @@ -185,7 +185,7 @@ export function prepareInputFields(
inputTypeComposer.removeField(inputFieldsOpts.remove);
}
if (inputFieldsOpts.required) {
inputTypeComposer.makeRequired(inputFieldsOpts.required);
inputTypeComposer.makeFieldNonNull(inputFieldsOpts.required);
}
}

Expand Down
Loading