Skip to content

refactor: due changes in [email protected] #37

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

Merged
merged 3 commits into from
Mar 15, 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
10 changes: 10 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"line-length": false,
"no-trailing-punctuation": {
"punctuation": ",;"
},
"no-inline-html": false,
"ol-prefix": false,
"first-line-h1": false,
"first-heading-h1": false
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"prettier.eslintIntegration": true,
"eslint.validate": [
"javascript",
],
"javascript.validate.enable": false
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![Greenkeeper badge](https://badges.greenkeeper.io/graphql-compose/graphql-compose-connection.svg)](https://greenkeeper.io/)

This is a plugin for [graphql-compose](https://github.com/graphql-compose/graphql-compose) family, which adds to the TypeComposer `connection` resolver.
This is a plugin for [graphql-compose](https://github.com/graphql-compose/graphql-compose) family, which adds to the ObjectTypeComposer `connection` resolver.

Live demo: [https://graphql-compose.herokuapp.com/](https://graphql-compose.herokuapp.com/)

Expand All @@ -33,9 +33,9 @@ Example
=======
```js
import composeWithConnection from 'graphql-compose-connection';
import userTypeComposer from './user.js';
import userTC from './user.js';

composeWithConnection(userTypeComposer, {
composeWithConnection(userTC, {
connectionResolverName: 'connection', // Default
findResolverName: 'findMany',
countResolverName: 'count',
Expand Down
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "graphql-compose-connection",
"version": "0.0.0-semantically-released",
"description": "Plugin for `graphql-compose` which provide a connection resolver for types.",
"license": "MIT",
"files": [
"lib",
"mjs",
Expand All @@ -19,39 +20,38 @@
"graphql-compose",
"relay"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/graphql-compose/graphql-compose-connection/issues"
},
"homepage": "https://github.com/graphql-compose/graphql-compose-connection",
"peerDependencies": {
"graphql-compose": ">=5.0.1 || >=4.0.0 || >=3.0.0"
"graphql-compose": ">=6.0.0"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/cli": "^7.2.3",
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-object-rest-spread": "^7.3.4",
"@babel/plugin-transform-flow-strip-types": "^7.3.4",
"@babel/plugin-transform-runtime": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/preset-flow": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^9.0.0",
"babel-jest": "^23.4.2",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.5.0",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^5.5.0",
"eslint": "^5.15.2",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-flowtype": "^2.50.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-prettier": "^2.6.2",
"flow-bin": "^0.80.0",
"graphql": "14.0.0",
"graphql-compose": "^5.0.1",
"jest": "^23.5.0",
"prettier": "^1.14.2",
"rimraf": "^2.6.2",
"semantic-release": "^15.9.12"
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-flowtype": "^3.4.2",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-prettier": "^3.0.1",
"flow-bin": "^0.95.1",
"graphql": "14.1.1",
"graphql-compose": "^6.0.1",
"jest": "^24.5.0",
"prettier": "^1.16.4",
"rimraf": "^2.6.3",
"semantic-release": "^15.13.3"
},
"config": {
"commitizen": {
Expand All @@ -75,7 +75,7 @@
"flow": "./node_modules/.bin/flow",
"test": "npm run coverage && npm run lint && npm run flow",
"link": "yarn build && yarn link graphql-compose && yarn link",
"unlink": "yarn unlink graphql-compose && yarn add graphql-compose",
"unlink": "rimraf node_modules && yarn install",
"semantic-release": "semantic-release"
}
}
8 changes: 8 additions & 0 deletions src/__mocks__/rootQueryTC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* @flow */

import { schemaComposer } from 'graphql-compose';

export const rootQueryTC = schemaComposer.createObjectTC({
name: 'RootQuery',
fields: {},
});
10 changes: 0 additions & 10 deletions src/__mocks__/rootQueryTypeComposer.js

This file was deleted.

12 changes: 6 additions & 6 deletions src/__mocks__/userTypeComposer.js → src/__mocks__/userTC.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */
/* eslint-disable no-param-reassign */

import { TypeComposer, Resolver } from 'graphql-compose';
import { schemaComposer } from 'graphql-compose';
import {
GraphQLString,
GraphQLObjectType,
Expand Down Expand Up @@ -29,7 +29,7 @@ export const UserType = new GraphQLObjectType({
},
});

export const userTypeComposer = new TypeComposer(UserType);
export const userTC = schemaComposer.createObjectTC(UserType);

export const userList = [
{ id: 1, name: 'user01', age: 11, gender: 'm' },
Expand Down Expand Up @@ -119,7 +119,7 @@ function prepareFilterFromArgs(resolveParams = {}) {
return filter;
}

export const findManyResolver = new Resolver({
export const findManyResolver = schemaComposer.createResolver({
name: 'findMany',
kind: 'query',
type: UserType,
Expand Down Expand Up @@ -156,9 +156,9 @@ export const findManyResolver = new Resolver({
return Promise.resolve(list);
},
});
userTypeComposer.setResolver('findMany', findManyResolver);
userTC.setResolver('findMany', findManyResolver);

export const countResolver = new Resolver({
export const countResolver = schemaComposer.createResolver({
name: 'count',
kind: 'query',
type: GraphQLInt,
Expand All @@ -169,7 +169,7 @@ export const countResolver = new Resolver({
return Promise.resolve(filteredUserList(userList, prepareFilterFromArgs(resolveParams)).length);
},
});
userTypeComposer.setResolver('count', countResolver);
userTC.setResolver('count', countResolver);

export const sortOptions: ConnectionSortMapOpts = {
ID_ASC: {
Expand Down
38 changes: 19 additions & 19 deletions src/__tests__/composeWithConnection-test.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
/* @flow */
/* eslint-disable no-param-reassign */

import { TypeComposer } from 'graphql-compose';
import { schemaComposer, ObjectTypeComposer } from 'graphql-compose';
import { GraphQLSchema, GraphQLList, GraphQLNonNull, graphql } from 'graphql-compose/lib/graphql';
import { composeWithConnection } from '../composeWithConnection';
import { userTypeComposer, sortOptions } from '../__mocks__/userTypeComposer';
import { rootQueryTypeComposer as rootQueryTC } from '../__mocks__/rootQueryTypeComposer';
import { userTC, sortOptions } from '../__mocks__/userTC';
import { rootQueryTC } from '../__mocks__/rootQueryTC';

describe('composeWithRelay', () => {
const userComposer = composeWithConnection(userTypeComposer, {
const userComposer = composeWithConnection(userTC, {
countResolverName: 'count',
findResolverName: 'findMany',
sort: sortOptions,
});

describe('basic checks', () => {
it('should return TypeComposer', () => {
expect(userComposer).toBeInstanceOf(TypeComposer);
it('should return ObjectTypeComposer', () => {
expect(userComposer).toBeInstanceOf(ObjectTypeComposer);
});

it('should throw error if first arg is not TypeComposer', () => {
it('should throw error if first arg is not ObjectTypeComposer', () => {
expect(() => {
const wrongArgs: any = [123];
composeWithConnection(...wrongArgs);
}).toThrowError('should provide TypeComposer instance');
}).toThrowError('should provide ObjectTypeComposer instance');
});

it('should throw error if options are empty', () => {
expect(() => {
const wrongArgs: any = [userTypeComposer];
const wrongArgs: any = [userTC];
composeWithConnection(...wrongArgs);
}).toThrowError('should provide non-empty options');
});

it('should not change `connection` resolver if exists', () => {
let myTC = TypeComposer.create('type Complex { a: String, b: Int }');
let myTC = schemaComposer.createObjectTC('type Complex { a: String, b: Int }');
myTC.addResolver({
name: 'connection',
resolve: () => 'mockData',
Expand All @@ -48,11 +48,11 @@ describe('composeWithRelay', () => {
});

expect(myTC.getResolver('connection')).toBeTruthy();
expect(myTC.getResolver('connection').resolve()).toBe('mockData');
expect(myTC.getResolver('connection').resolve({})).toBe('mockData');
});

it('should add resolver with user-specified name', () => {
let myTC = TypeComposer.create('type CustomComplex { a: String, b: Int }');
let myTC = schemaComposer.createObjectTC('type CustomComplex { a: String, b: Int }');
myTC.addResolver({
name: 'count',
resolve: () => 1,
Expand All @@ -73,7 +73,7 @@ describe('composeWithRelay', () => {
});

it('should add two connection resolvers', () => {
let myTC = TypeComposer.create('type CustomComplex { a: String, b: Int }');
let myTC = schemaComposer.createObjectTC('type CustomComplex { a: String, b: Int }');
myTC.addResolver({
name: 'count',
resolve: () => 1,
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('composeWithRelay', () => {
describe('check `connection` resolver props', () => {
const rsv = userComposer.getResolver('connection');
const type: any = rsv.getType();
const tc = new TypeComposer(type);
const tc = schemaComposer.createObjectTC(type);

it('should exists', () => {
expect(rsv).toBeTruthy();
Expand All @@ -118,7 +118,7 @@ describe('composeWithRelay', () => {
});

it('should apply first sort ID_ASC by default', async () => {
rootQueryTC.setField('userConnection', userTypeComposer.getResolver('connection'));
rootQueryTC.setField('userConnection', userTC.getResolver('connection'));
const schema = new GraphQLSchema({
query: rootQueryTC.getType(),
});
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('composeWithRelay', () => {
});

it('should able to change `sort` on AGE_ID_DESC', async () => {
rootQueryTC.setField('userConnection', userTypeComposer.getResolver('connection'));
rootQueryTC.setField('userConnection', userTC.getResolver('connection'));
const schema = new GraphQLSchema({
query: rootQueryTC.getType(),
});
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('composeWithRelay', () => {

describe('fragments fields projection of graphql-compose', () => {
it('should return object', async () => {
rootQueryTC.setField('userConnection', userTypeComposer.getResolver('connection'));
rootQueryTC.setField('userConnection', userTC.getResolver('connection'));
const schema = new GraphQLSchema({
query: rootQueryTC.getType(),
});
Expand Down Expand Up @@ -285,7 +285,7 @@ describe('composeWithRelay', () => {

rootQueryTC.setField(
'userConnection',
userTypeComposer.getResolver('connection').wrapResolve(next => rp => {
userTC.getResolver('connection').wrapResolve(next => rp => {
const result = next(rp);
topResolveParams = rp;
return result;
Expand Down Expand Up @@ -315,7 +315,7 @@ describe('composeWithRelay', () => {

rootQueryTC.setField(
'userConnection',
userTypeComposer.getResolver('connection').wrapResolve(next => rp => {
userTC.getResolver('connection').wrapResolve(next => rp => {
const result = next(rp);
topResolveParams = rp;
return result;
Expand Down
Loading