Skip to content

Commit 0cd902b

Browse files
authored
refactor: upgrade GraphQL dependencies (#7970)
1 parent 0dc2843 commit 0cd902b

10 files changed

+128
-334
lines changed

package-lock.json

+43-220
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
],
2020
"license": "BSD-3-Clause",
2121
"dependencies": {
22-
"@graphql-tools/stitch": "6.2.4",
23-
"@graphql-tools/utils": "6.2.4",
2422
"@graphql-yoga/node": "2.6.0",
23+
"@graphql-tools/merge": "8.2.11",
24+
"@graphql-tools/schema": "8.3.11",
25+
"@graphql-tools/utils": "8.6.10",
2526
"@parse/fs-files-adapter": "1.2.2",
2627
"@parse/push-adapter": "4.1.2",
2728
"bcryptjs": "2.4.3",
@@ -31,10 +32,10 @@
3132
"deepcopy": "2.1.0",
3233
"express": "4.18.1",
3334
"follow-redirects": "1.15.0",
34-
"graphql": "15.8.0",
35+
"graphql": "16.5.0",
3536
"graphql-list-fields": "2.0.2",
36-
"graphql-relay": "0.7.0",
3737
"graphql-tag": "2.12.6",
38+
"graphql-relay": "0.10.0",
3839
"intersect": "1.0.1",
3940
"jsonwebtoken": "8.5.1",
4041
"jwks-rsa": "2.1.2",
@@ -58,6 +59,7 @@
5859
"ws": "8.6.0"
5960
},
6061
"devDependencies": {
62+
"graphql-tag": "2.12.6",
6163
"@actions/core": "1.2.6",
6264
"@apollo/client": "3.6.1",
6365
"@babel/cli": "7.10.0",

spec/AuthenticationAdapters.spec.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,11 @@ describe('AuthenticationProviders', function () {
500500
const provider = getMockMyOauthProvider();
501501
Parse.User._registerAuthenticationProvider(provider);
502502
await Parse.User._logInWith('myoauth');
503-
expect(spy).toHaveBeenCalledWith({ usage: 'auth.myoauth', solution: 'auth.myoauth.enabled: true' });
503+
expect(spy).toHaveBeenCalledWith({
504+
usage: 'auth.myoauth',
505+
solution: 'auth.myoauth.enabled: true',
506+
});
504507
});
505-
506508
});
507509

508510
describe('instagram auth adapter', () => {

spec/ParseGraphQLServer.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const { getMainDefinition } = require('apollo-utilities');
1212
const { createUploadLink } = require('apollo-upload-client');
1313
const { SubscriptionClient } = require('subscriptions-transport-ws');
1414
const { WebSocketLink } = require('@apollo/client/link/ws');
15+
const { mergeSchemas } = require('@graphql-tools/schema');
1516
const {
1617
ApolloClient,
1718
InMemoryCache,
@@ -10459,7 +10460,7 @@ describe('ParseGraphQLServer', () => {
1045910460
});
1046010461

1046110462
describe('Custom API', () => {
10462-
describe('GraphQL Schema Based', () => {
10463+
describe('SDL based', () => {
1046310464
let httpServer;
1046410465
const headers = {
1046510466
'X-Parse-Application-Id': 'test',
@@ -10582,7 +10583,7 @@ describe('ParseGraphQLServer', () => {
1058210583
});
1058310584
});
1058410585

10585-
describe('SDL Based', () => {
10586+
describe('GraphQL Schema Based', () => {
1058610587
let httpServer;
1058710588
const headers = {
1058810589
'X-Parse-Application-Id': 'test',
@@ -10879,8 +10880,7 @@ describe('ParseGraphQLServer', () => {
1087910880
httpServer = http.createServer(expressApp);
1088010881
parseGraphQLServer = new ParseGraphQLServer(parseServer, {
1088110882
graphQLPath: '/graphql',
10882-
graphQLCustomTypeDefs: ({ autoSchema, stitchSchemas }) =>
10883-
stitchSchemas({ subschemas: [autoSchema] }),
10883+
graphQLCustomTypeDefs: ({ autoSchema }) => mergeSchemas({ schemas: [autoSchema] }),
1088410884
});
1088510885

1088610886
parseGraphQLServer.applyGraphQL(expressApp);

src/Controllers/SchemaController.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const requiredColumns = Object.freeze({
158158
write: {
159159
_Product: ['productIdentifier', 'icon', 'order', 'title', 'subtitle'],
160160
_Role: ['name', 'ACL'],
161-
}
161+
},
162162
});
163163

164164
const invalidColumns = ['length'];

src/GraphQL/ParseGraphQLSchema.js

+10-44
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Parse from 'parse/node';
22
import { GraphQLSchema, GraphQLObjectType, DocumentNode, GraphQLNamedType } from 'graphql';
3-
import { stitchSchemas } from '@graphql-tools/stitch';
3+
import { mergeSchemas } from '@graphql-tools/schema';
4+
import { mergeTypeDefs } from '@graphql-tools/merge';
45
import { isDeepStrictEqual } from 'util';
5-
import { SchemaDirectiveVisitor } from '@graphql-tools/utils';
66
import requiredParameter from '../requiredParameter';
77
import * as defaultGraphQLTypes from './loaders/defaultGraphQLTypes';
88
import * as parseClassTypes from './loaders/parseClassTypes';
@@ -203,9 +203,8 @@ class ParseGraphQLSchema {
203203

204204
if (this.graphQLCustomTypeDefs) {
205205
schemaDirectives.load(this);
206-
207206
if (typeof this.graphQLCustomTypeDefs.getTypeMap === 'function') {
208-
// In following code we use underscore attr to avoid js var un ref
207+
// In following code we use underscore attr to keep the direct variable reference
209208
const customGraphQLSchemaTypeMap = this.graphQLCustomTypeDefs._typeMap;
210209
const findAndReplaceLastType = (parent, key) => {
211210
if (parent[key].name) {
@@ -280,51 +279,18 @@ class ParseGraphQLSchema {
280279
this.graphQLSchema = await this.graphQLCustomTypeDefs({
281280
directivesDefinitionsSchema: this.graphQLSchemaDirectivesDefinitions,
282281
autoSchema: this.graphQLAutoSchema,
283-
stitchSchemas,
282+
graphQLSchemaDirectives: this.graphQLSchemaDirectives,
284283
});
285284
} else {
286-
this.graphQLSchema = stitchSchemas({
287-
schemas: [
288-
this.graphQLSchemaDirectivesDefinitions,
289-
this.graphQLAutoSchema,
285+
this.graphQLSchema = mergeSchemas({
286+
schemas: [this.graphQLAutoSchema],
287+
typeDefs: mergeTypeDefs([
290288
this.graphQLCustomTypeDefs,
291-
],
292-
mergeDirectives: true,
289+
this.graphQLSchemaDirectivesDefinitions,
290+
]),
293291
});
292+
this.graphQLSchema = this.graphQLSchemaDirectives(this.graphQLSchema);
294293
}
295-
296-
// Only merge directive when string schema provided
297-
const graphQLSchemaTypeMap = this.graphQLSchema.getTypeMap();
298-
Object.keys(graphQLSchemaTypeMap).forEach(graphQLSchemaTypeName => {
299-
const graphQLSchemaType = graphQLSchemaTypeMap[graphQLSchemaTypeName];
300-
if (
301-
typeof graphQLSchemaType.getFields === 'function' &&
302-
this.graphQLCustomTypeDefs.definitions
303-
) {
304-
const graphQLCustomTypeDef = this.graphQLCustomTypeDefs.definitions.find(
305-
definition => definition.name.value === graphQLSchemaTypeName
306-
);
307-
if (graphQLCustomTypeDef) {
308-
const graphQLSchemaTypeFieldMap = graphQLSchemaType.getFields();
309-
Object.keys(graphQLSchemaTypeFieldMap).forEach(graphQLSchemaTypeFieldName => {
310-
const graphQLSchemaTypeField = graphQLSchemaTypeFieldMap[graphQLSchemaTypeFieldName];
311-
if (!graphQLSchemaTypeField.astNode) {
312-
const astNode = graphQLCustomTypeDef.fields.find(
313-
field => field.name.value === graphQLSchemaTypeFieldName
314-
);
315-
if (astNode) {
316-
graphQLSchemaTypeField.astNode = astNode;
317-
}
318-
}
319-
});
320-
}
321-
}
322-
});
323-
324-
SchemaDirectiveVisitor.visitSchemaDirectives(
325-
this.graphQLSchema,
326-
this.graphQLSchemaDirectives
327-
);
328294
} else {
329295
this.graphQLSchema = this.graphQLAutoSchema;
330296
}

src/GraphQL/loaders/defaultGraphQLTypes.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1210,12 +1210,12 @@ const loadArrayResult = (parseGraphQLSchema, parseClassesArray) => {
12101210
resolveType: value => {
12111211
if (value.__type === 'Object' && value.className && value.objectId) {
12121212
if (parseGraphQLSchema.parseClassTypes[value.className]) {
1213-
return parseGraphQLSchema.parseClassTypes[value.className].classGraphQLOutputType;
1213+
return parseGraphQLSchema.parseClassTypes[value.className].classGraphQLOutputType.name;
12141214
} else {
1215-
return ELEMENT;
1215+
return ELEMENT.name;
12161216
}
12171217
} else {
1218-
return ELEMENT;
1218+
return ELEMENT.name;
12191219
}
12201220
},
12211221
});

src/GraphQL/loaders/defaultRelaySchema.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const load = parseGraphQLSchema => {
3939
}
4040
},
4141
obj => {
42-
return parseGraphQLSchema.parseClassTypes[obj.className].classGraphQLOutputType;
42+
return parseGraphQLSchema.parseClassTypes[obj.className].classGraphQLOutputType.name;
4343
}
4444
);
4545

+43-42
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
1-
import gql from 'graphql-tag';
2-
import { SchemaDirectiveVisitor } from '@graphql-tools/utils';
1+
import { mapSchema, getDirective, MapperKind } from '@graphql-tools/utils';
32
import { FunctionsRouter } from '../../Routers/FunctionsRouter';
43

5-
export const definitions = gql`
4+
export const definitions = `
65
directive @resolve(to: String) on FIELD_DEFINITION
76
directive @mock(with: Any!) on FIELD_DEFINITION
87
`;
98

109
const load = parseGraphQLSchema => {
1110
parseGraphQLSchema.graphQLSchemaDirectivesDefinitions = definitions;
1211

13-
class ResolveDirectiveVisitor extends SchemaDirectiveVisitor {
14-
visitFieldDefinition(field) {
15-
field.resolve = async (_source, args, context) => {
16-
try {
17-
const { config, auth, info } = context;
18-
19-
let functionName = field.name;
20-
if (this.args.to) {
21-
functionName = this.args.to;
22-
}
23-
24-
return (
25-
await FunctionsRouter.handleCloudFunction({
26-
params: {
27-
functionName,
28-
},
29-
config,
30-
auth,
31-
info,
32-
body: args,
33-
})
34-
).response.result;
35-
} catch (e) {
36-
parseGraphQLSchema.handleError(e);
12+
const resolveDirective = schema =>
13+
mapSchema(schema, {
14+
[MapperKind.OBJECT_FIELD]: fieldConfig => {
15+
const directive = getDirective(schema, fieldConfig, 'resolve')?.[0];
16+
if (directive) {
17+
const { to: targetCloudFunction } = directive;
18+
fieldConfig.resolve = async (_source, args, context, gqlInfo) => {
19+
try {
20+
const { config, auth, info } = context;
21+
const functionName = targetCloudFunction || gqlInfo.fieldName;
22+
return (
23+
await FunctionsRouter.handleCloudFunction({
24+
params: {
25+
functionName,
26+
},
27+
config,
28+
auth,
29+
info,
30+
body: args,
31+
})
32+
).response.result;
33+
} catch (e) {
34+
parseGraphQLSchema.handleError(e);
35+
}
36+
};
3737
}
38-
};
39-
}
40-
}
41-
42-
parseGraphQLSchema.graphQLSchemaDirectives.resolve = ResolveDirectiveVisitor;
43-
44-
class MockDirectiveVisitor extends SchemaDirectiveVisitor {
45-
visitFieldDefinition(field) {
46-
field.resolve = () => {
47-
return this.args.with;
48-
};
49-
}
50-
}
38+
return fieldConfig;
39+
},
40+
});
41+
42+
const mockDirective = schema =>
43+
mapSchema(schema, {
44+
[MapperKind.OBJECT_FIELD]: fieldConfig => {
45+
const directive = getDirective(schema, fieldConfig, 'mock')?.[0];
46+
if (directive) {
47+
const { with: mockValue } = directive;
48+
fieldConfig.resolve = async () => mockValue;
49+
}
50+
return fieldConfig;
51+
},
52+
});
5153

52-
parseGraphQLSchema.graphQLSchemaDirectives.mock = MockDirectiveVisitor;
54+
parseGraphQLSchema.graphQLSchemaDirectives = schema => mockDirective(resolveDirective(schema));
5355
};
54-
5556
export { load };

src/GraphQL/loaders/schemaTypes.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ const SCHEMA_FIELD = new GraphQLInterfaceType({
2929
},
3030
resolveType: value =>
3131
({
32-
String: SCHEMA_STRING_FIELD,
33-
Number: SCHEMA_NUMBER_FIELD,
34-
Boolean: SCHEMA_BOOLEAN_FIELD,
35-
Array: SCHEMA_ARRAY_FIELD,
36-
Object: SCHEMA_OBJECT_FIELD,
37-
Date: SCHEMA_DATE_FIELD,
38-
File: SCHEMA_FILE_FIELD,
39-
GeoPoint: SCHEMA_GEO_POINT_FIELD,
40-
Polygon: SCHEMA_POLYGON_FIELD,
41-
Bytes: SCHEMA_BYTES_FIELD,
42-
Pointer: SCHEMA_POINTER_FIELD,
43-
Relation: SCHEMA_RELATION_FIELD,
44-
ACL: SCHEMA_ACL_FIELD,
32+
String: SCHEMA_STRING_FIELD.name,
33+
Number: SCHEMA_NUMBER_FIELD.name,
34+
Boolean: SCHEMA_BOOLEAN_FIELD.name,
35+
Array: SCHEMA_ARRAY_FIELD.name,
36+
Object: SCHEMA_OBJECT_FIELD.name,
37+
Date: SCHEMA_DATE_FIELD.name,
38+
File: SCHEMA_FILE_FIELD.name,
39+
GeoPoint: SCHEMA_GEO_POINT_FIELD.name,
40+
Polygon: SCHEMA_POLYGON_FIELD.name,
41+
Bytes: SCHEMA_BYTES_FIELD.name,
42+
Pointer: SCHEMA_POINTER_FIELD.name,
43+
Relation: SCHEMA_RELATION_FIELD.name,
44+
ACL: SCHEMA_ACL_FIELD.name,
4545
}[value.type]),
4646
});
4747

0 commit comments

Comments
 (0)