Skip to content

Commit 212af10

Browse files
committed
refactor: migrate on graphql-compose@6.0.0
1 parent 1ad1d8b commit 212af10

34 files changed

+2900
-3028
lines changed

.eslintrc.js

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
module.exports = {
2-
"env": {
3-
"node": true,
4-
"es6": true,
5-
"jest": true,
2+
env: {
3+
node: true,
4+
es6: true,
5+
jest: true,
66
},
7-
"extends": [
8-
"airbnb-base",
9-
"prettier"
10-
],
11-
"plugins": [
12-
"prettier"
13-
],
14-
"env": {
15-
"jasmine": true,
16-
"jest": true
7+
extends: ['airbnb-base', 'prettier'],
8+
plugins: ['prettier'],
9+
env: {
10+
jasmine: true,
11+
jest: true,
1712
},
18-
"parser": "babel-eslint",
19-
"rules": {
20-
"import/no-unresolved": [2, {commonjs: true, amd: true}],
21-
"no-underscore-dangle": 0,
22-
"arrow-body-style": 0,
23-
"import/no-extraneous-dependencies": 0,
24-
"import/imports-first": 0,
25-
"import/no-cycle": 0,
26-
"no-console": 0,
27-
"no-restricted-syntax": 0,
28-
"global-require": 0,
29-
"import/no-dynamic-require": 0,
30-
"import/prefer-default-export": 0,
31-
"no-use-before-define": 0,
32-
"no-param-reassign": 0,
33-
"func-names": 0,
34-
"prettier/prettier": ["error", {
35-
"printWidth": 100,
36-
"singleQuote": true,
37-
"trailingComma": "es5",
38-
}]
39-
}
13+
parser: 'babel-eslint',
14+
rules: {
15+
'import/no-unresolved': [2, { commonjs: true, amd: true }],
16+
'no-underscore-dangle': 0,
17+
'arrow-body-style': 0,
18+
'import/no-extraneous-dependencies': 0,
19+
'import/imports-first': 0,
20+
'import/no-cycle': 0,
21+
'no-console': 0,
22+
'no-restricted-syntax': 0,
23+
'global-require': 0,
24+
'import/no-dynamic-require': 0,
25+
'import/prefer-default-export': 0,
26+
'no-use-before-define': 0,
27+
'no-param-reassign': 0,
28+
'func-names': 0,
29+
'prettier/prettier': [
30+
'error',
31+
{
32+
printWidth: 100,
33+
singleQuote: true,
34+
trailingComma: 'es5',
35+
},
36+
],
37+
},
38+
globals: { Class: true },
4039
};

.markdownlint.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"line-length": false,
3+
"no-trailing-punctuation": {
4+
"punctuation": ",;"
5+
},
6+
"no-inline-html": false,
7+
"ol-prefix": false,
8+
"first-line-h1": false,
9+
"first-heading-h1": false
10+
}

.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+
}

examples/elasticsearch/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ export default {
1010
'This schema provides full API available in the <a href="https://github.com/elastic/elasticsearch-js" target="_blank">official elasticsearch module</a>.',
1111
github: 'https://github.com/nodkz/graphql-compose-examples/tree/master/examples/elasticsearch',
1212
queries: [
13+
{
14+
title: 'Elastic search API 6.0',
15+
query: `
16+
query {
17+
elastic60(host: "http://user:pass@example.com:9200") {
18+
search(q: "JavaScript")
19+
}
20+
}
21+
`,
22+
},
1323
{
1424
title: 'Elastic search API 5.0',
1525
query: `

examples/elasticsearch/schema.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,33 @@ function checkHost(host): void {
1616

1717
const schemaComposer = new SchemaComposer();
1818

19+
schemaComposer.Query.setField('elastic60', {
20+
description: 'Elastic v6.0',
21+
type: schemaComposer.createObjectTC({
22+
name: 'Elastic60',
23+
fields: new ElasticApiParser({ version: '6_0', prefix: 'Elastic60' }).generateFieldMap(),
24+
}),
25+
args: {
26+
host: {
27+
type: 'String',
28+
defaultValue: 'http://user:pass@example.com:9200',
29+
},
30+
},
31+
resolve: (src, args, context) => {
32+
checkHost(args.host);
33+
context.elasticClient = new elasticsearch.Client({
34+
// eslint-disable-line no-param-reassign
35+
host: args.host,
36+
apiVersion: '6.0',
37+
requestTimeout: 5000,
38+
});
39+
return {};
40+
},
41+
});
42+
1943
schemaComposer.Query.setField('elastic50', {
2044
description: 'Elastic v5.0',
21-
type: schemaComposer.TypeComposer.create({
45+
type: schemaComposer.createObjectTC({
2246
name: 'Elastic50',
2347
fields: new ElasticApiParser({ version: '5_0', prefix: 'Elastic50' }).generateFieldMap(),
2448
}),
@@ -42,7 +66,7 @@ schemaComposer.Query.setField('elastic50', {
4266

4367
schemaComposer.Query.setField('elastic24', {
4468
description: 'Elastic v2.4',
45-
type: schemaComposer.TypeComposer.create({
69+
type: schemaComposer.createObjectTC({
4670
name: 'Elastic24',
4771
fields: new ElasticApiParser({ version: '2_4', prefix: 'Elastic24' }).generateFieldMap(),
4872
}),
@@ -66,7 +90,7 @@ schemaComposer.Query.setField('elastic24', {
6690

6791
schemaComposer.Query.setField('elastic17', {
6892
description: 'Elastic v1.7',
69-
type: schemaComposer.TypeComposer.create({
93+
type: schemaComposer.createObjectTC({
7094
name: 'Elastic17',
7195
fields: new ElasticApiParser({ version: '5_0', prefix: 'Elastic17' }).generateFieldMap(),
7296
}),

examples/mongooseDiscriminators/__tests__/queriesFromIndex-test.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@ beforeAll(async () => {
1616
mongoServer = new MongodbMemoryServer({ instance: { dbName: 'user' } });
1717
const mongoUri = await mongoServer.getConnectionString();
1818
const opts = { useNewUrlParser: true };
19-
mongoose.connect(
20-
mongoUri,
21-
opts
22-
);
23-
con = await MongoClient.connect(
24-
mongoUri,
25-
opts
26-
);
19+
mongoose.connect(mongoUri, opts);
20+
con = await MongoClient.connect(mongoUri, opts);
2721
db = con.db('user');
2822
await seed(db);
2923
// take time to mongo create indexes if needed

examples/mongooseDiscriminators/models.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import mongoose from 'mongoose';
44
import { composeWithMongooseDiscriminators } from 'graphql-compose-mongoose';
5-
import { schemaComposer } from './schemaComposer';
5+
import { type ObjectTypeComposer } from 'graphql-compose';
6+
import { schemaComposer, type TContext } from './schemaComposer';
67

78
// pick a discriminatorKey
89
const DKey = 'type';
@@ -55,7 +56,16 @@ export const CharacterModel = mongoose.model('Character', CharacterSchema);
5556
export const DroidModel = CharacterModel.discriminator(enumCharacterType.DROID, DroidSchema);
5657
export const PersonModel = CharacterModel.discriminator(enumCharacterType.PERSON, PersonSchema);
5758

58-
export const CharacterDTC = composeWithMongooseDiscriminators(CharacterModel, { schemaComposer });
59+
export const CharacterDTC = composeWithMongooseDiscriminators<any, TContext>(CharacterModel, {
60+
schemaComposer,
61+
});
62+
63+
type DroidT = any;
64+
export const DroidTC: ObjectTypeComposer<DroidT, TContext> = CharacterDTC.discriminator<DroidT>(
65+
DroidModel
66+
);
5967

60-
export const DroidTC = CharacterDTC.discriminator(DroidModel);
61-
export const PersonTC = CharacterDTC.discriminator(PersonModel);
68+
type PersonT = any;
69+
export const PersonTC: ObjectTypeComposer<PersonT, TContext> = CharacterDTC.discriminator<PersonT>(
70+
PersonModel
71+
);

examples/mongooseDiscriminators/schemaComposer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@
99

1010
import { SchemaComposer } from 'graphql-compose';
1111

12-
export const schemaComposer = new SchemaComposer();
12+
export type TContext = {
13+
ip: string,
14+
};
15+
16+
export const schemaComposer: SchemaComposer<TContext> = new SchemaComposer();

examples/northwind/__tests__/queriesFromIndex-test.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,11 @@ beforeAll(async () => {
1616
mongoServer = new MongodbMemoryServer({ instance: { dbName: 'northwind' } });
1717
const mongoUri = await mongoServer.getConnectionString();
1818
const opts = { useNewUrlParser: true };
19-
mongoose.connect(
20-
mongoUri,
21-
opts
22-
);
19+
mongoose.connect(mongoUri, opts);
2320
mongoose.connection.once('disconnected', () => {
2421
console.log('MongoDB disconnected!');
2522
});
26-
con = await MongoClient.connect(
27-
mongoUri,
28-
opts
29-
);
23+
con = await MongoClient.connect(mongoUri, opts);
3024
db = con.db('northwind');
3125
await seed(db);
3226
// take time to mongo create indexes if needed

examples/northwind/auth/allowOnlyForLocalhost.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* @flow */
22

3-
import type { Resolver } from '../schemaComposer';
3+
import type { Resolver } from 'graphql-compose';
44

5-
export default function allowOnlyForLocalhost(resolvers: { [name: string]: Resolver }) {
5+
export default function allowOnlyForLocalhost(resolvers: {
6+
[name: string]: Resolver<any, any, any>,
7+
}) {
68
const secureResolvers = {};
79
Object.keys(resolvers).forEach(k => {
810
secureResolvers[k] = resolvers[k].wrapResolve(next => rp => {

examples/northwind/data/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
> **©Fargo**
44
55
This is a sample data of some trading company:
6+
67
- Initial SQLish schema can be found in [csv folder](https://github.com/nodkz/graphql-compose-mongoose-example/tree/master/examples/northwind/data/csv).
78
- Modified/normalized MongoDBish schema in [json folder](https://github.com/nodkz/graphql-compose-mongoose-example/tree/master/examples/northwind/data/json).
89

@@ -17,6 +18,7 @@ File `mongo-shell-transform.js` is a `mongo shell` script, that makes data trans
1718
![Northwind MongoDB Schema](./northwind-mongodb-schema.svg)
1819

1920
### How schema was transformed
21+
2022
- **categories** (8 docs)
2123
- categoryID: int
2224
- categoryName->name: string

examples/northwind/models/addressSchema.js

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

3-
import mongoose from 'mongoose';
3+
import { Schema } from 'mongoose';
44

5-
export const AddressSchema = new mongoose.Schema(
5+
export const AddressSchema: Schema<any> = new Schema(
66
{
77
street: String,
88
city: String,

examples/northwind/models/category.js

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

3-
import mongoose from 'mongoose';
3+
import { Schema, model } from 'mongoose';
44
import { composeWithMongoose, composeWithRelay } from '../schemaComposer';
55
import { ProductTC } from './product';
66

7-
export const CategorySchema = new mongoose.Schema(
7+
export const CategorySchema: Schema<any> = new Schema(
88
{
99
categoryID: {
1010
type: Number,
@@ -22,9 +22,9 @@ export const CategorySchema = new mongoose.Schema(
2222
}
2323
);
2424

25-
export const Category = mongoose.model('Category', CategorySchema);
25+
export const Category = model('Category', CategorySchema);
2626

27-
export const CategoryTC = composeWithRelay(composeWithMongoose(Category));
27+
export const CategoryTC = composeWithRelay(composeWithMongoose<any>(Category));
2828

2929
CategoryTC.addRelation('productConnection', {
3030
resolver: () => ProductTC.getResolver('connection'),

examples/northwind/models/customer.js

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

3-
import mongoose from 'mongoose';
3+
import { Schema, model } from 'mongoose';
44
import { composeWithMongoose, composeWithRelay } from '../schemaComposer';
55
import { AddressSchema } from './addressSchema';
66
import { OrderTC } from './order';
77

8-
export const CustomerSchema = new mongoose.Schema(
8+
export const CustomerSchema: Schema<any> = new Schema(
99
{
1010
customerID: {
1111
type: String,
@@ -26,9 +26,9 @@ export const CustomerSchema = new mongoose.Schema(
2626
}
2727
);
2828

29-
export const Customer = mongoose.model('Customer', CustomerSchema);
29+
export const Customer = model('Customer', CustomerSchema);
3030

31-
export const CustomerTC = composeWithRelay(composeWithMongoose(Customer));
31+
export const CustomerTC = composeWithRelay(composeWithMongoose<any>(Customer));
3232

3333
CustomerTC.addRelation('orderConnection', {
3434
resolver: () => OrderTC.getResolver('connection'),

examples/northwind/models/employee.js

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

3-
import mongoose from 'mongoose';
3+
import { Schema, model } from 'mongoose';
44
import { composeWithMongoose, composeWithRelay } from '../schemaComposer';
55
import { AddressSchema } from './addressSchema';
66
import { OrderTC } from './order';
77

8-
export const EmployeeSchema = new mongoose.Schema(
8+
export const EmployeeSchema: Schema<any> = new Schema(
99
{
1010
employeeID: {
1111
type: Number,
@@ -61,9 +61,9 @@ EmployeeSchema.index(
6161
}
6262
);
6363

64-
export const Employee = mongoose.model('Employee', EmployeeSchema);
64+
export const Employee = model('Employee', EmployeeSchema);
6565

66-
export const EmployeeTC = composeWithRelay(composeWithMongoose(Employee));
66+
export const EmployeeTC = composeWithRelay(composeWithMongoose<any>(Employee));
6767

6868
const findManyResolver = EmployeeTC.getResolver('findMany').addFilterArg({
6969
name: 'fullTextSearch',

examples/northwind/models/order.js

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

3-
import mongoose from 'mongoose';
3+
import { Schema, model } from 'mongoose';
44
import { composeWithMongoose, composeWithRelay } from '../schemaComposer';
55
import { AddressSchema } from './addressSchema';
66
import { CustomerTC } from './customer';
77
import { EmployeeTC } from './employee';
88
import { ShipperTC } from './shipper';
99
import { ProductTC } from './product';
1010

11-
export const OrderDetailsSchema = new mongoose.Schema(
11+
export const OrderDetailsSchema: Schema<any> = new Schema(
1212
{
1313
productID: Number,
1414
unitPrice: Number,
@@ -20,7 +20,7 @@ export const OrderDetailsSchema = new mongoose.Schema(
2020
}
2121
);
2222

23-
export const OrderSchema = new mongoose.Schema(
23+
export const OrderSchema: Schema<any> = new Schema(
2424
{
2525
orderID: {
2626
type: Number,
@@ -47,9 +47,9 @@ export const OrderSchema = new mongoose.Schema(
4747
}
4848
);
4949

50-
export const Order = mongoose.model('Order', OrderSchema);
50+
export const Order = model('Order', OrderSchema);
5151

52-
export const OrderTC = composeWithRelay(composeWithMongoose(Order));
52+
export const OrderTC = composeWithRelay(composeWithMongoose<any>(Order));
5353

5454
OrderTC.addRelation('customer', {
5555
resolver: () => CustomerTC.getResolver('findOne'),

0 commit comments

Comments
 (0)