refactor: upgrade GraphQL dependencies (#7970)
This commit is contained in:
@@ -1210,12 +1210,12 @@ const loadArrayResult = (parseGraphQLSchema, parseClassesArray) => {
|
||||
resolveType: value => {
|
||||
if (value.__type === 'Object' && value.className && value.objectId) {
|
||||
if (parseGraphQLSchema.parseClassTypes[value.className]) {
|
||||
return parseGraphQLSchema.parseClassTypes[value.className].classGraphQLOutputType;
|
||||
return parseGraphQLSchema.parseClassTypes[value.className].classGraphQLOutputType.name;
|
||||
} else {
|
||||
return ELEMENT;
|
||||
return ELEMENT.name;
|
||||
}
|
||||
} else {
|
||||
return ELEMENT;
|
||||
return ELEMENT.name;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -39,7 +39,7 @@ const load = parseGraphQLSchema => {
|
||||
}
|
||||
},
|
||||
obj => {
|
||||
return parseGraphQLSchema.parseClassTypes[obj.className].classGraphQLOutputType;
|
||||
return parseGraphQLSchema.parseClassTypes[obj.className].classGraphQLOutputType.name;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import gql from 'graphql-tag';
|
||||
import { SchemaDirectiveVisitor } from '@graphql-tools/utils';
|
||||
import { mapSchema, getDirective, MapperKind } from '@graphql-tools/utils';
|
||||
import { FunctionsRouter } from '../../Routers/FunctionsRouter';
|
||||
|
||||
export const definitions = gql`
|
||||
export const definitions = `
|
||||
directive @resolve(to: String) on FIELD_DEFINITION
|
||||
directive @mock(with: Any!) on FIELD_DEFINITION
|
||||
`;
|
||||
@@ -10,46 +9,48 @@ export const definitions = gql`
|
||||
const load = parseGraphQLSchema => {
|
||||
parseGraphQLSchema.graphQLSchemaDirectivesDefinitions = definitions;
|
||||
|
||||
class ResolveDirectiveVisitor extends SchemaDirectiveVisitor {
|
||||
visitFieldDefinition(field) {
|
||||
field.resolve = async (_source, args, context) => {
|
||||
try {
|
||||
const { config, auth, info } = context;
|
||||
|
||||
let functionName = field.name;
|
||||
if (this.args.to) {
|
||||
functionName = this.args.to;
|
||||
}
|
||||
|
||||
return (
|
||||
await FunctionsRouter.handleCloudFunction({
|
||||
params: {
|
||||
functionName,
|
||||
},
|
||||
config,
|
||||
auth,
|
||||
info,
|
||||
body: args,
|
||||
})
|
||||
).response.result;
|
||||
} catch (e) {
|
||||
parseGraphQLSchema.handleError(e);
|
||||
const resolveDirective = schema =>
|
||||
mapSchema(schema, {
|
||||
[MapperKind.OBJECT_FIELD]: fieldConfig => {
|
||||
const directive = getDirective(schema, fieldConfig, 'resolve')?.[0];
|
||||
if (directive) {
|
||||
const { to: targetCloudFunction } = directive;
|
||||
fieldConfig.resolve = async (_source, args, context, gqlInfo) => {
|
||||
try {
|
||||
const { config, auth, info } = context;
|
||||
const functionName = targetCloudFunction || gqlInfo.fieldName;
|
||||
return (
|
||||
await FunctionsRouter.handleCloudFunction({
|
||||
params: {
|
||||
functionName,
|
||||
},
|
||||
config,
|
||||
auth,
|
||||
info,
|
||||
body: args,
|
||||
})
|
||||
).response.result;
|
||||
} catch (e) {
|
||||
parseGraphQLSchema.handleError(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
return fieldConfig;
|
||||
},
|
||||
});
|
||||
|
||||
parseGraphQLSchema.graphQLSchemaDirectives.resolve = ResolveDirectiveVisitor;
|
||||
const mockDirective = schema =>
|
||||
mapSchema(schema, {
|
||||
[MapperKind.OBJECT_FIELD]: fieldConfig => {
|
||||
const directive = getDirective(schema, fieldConfig, 'mock')?.[0];
|
||||
if (directive) {
|
||||
const { with: mockValue } = directive;
|
||||
fieldConfig.resolve = async () => mockValue;
|
||||
}
|
||||
return fieldConfig;
|
||||
},
|
||||
});
|
||||
|
||||
class MockDirectiveVisitor extends SchemaDirectiveVisitor {
|
||||
visitFieldDefinition(field) {
|
||||
field.resolve = () => {
|
||||
return this.args.with;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
parseGraphQLSchema.graphQLSchemaDirectives.mock = MockDirectiveVisitor;
|
||||
parseGraphQLSchema.graphQLSchemaDirectives = schema => mockDirective(resolveDirective(schema));
|
||||
};
|
||||
|
||||
export { load };
|
||||
|
||||
@@ -29,19 +29,19 @@ const SCHEMA_FIELD = new GraphQLInterfaceType({
|
||||
},
|
||||
resolveType: value =>
|
||||
({
|
||||
String: SCHEMA_STRING_FIELD,
|
||||
Number: SCHEMA_NUMBER_FIELD,
|
||||
Boolean: SCHEMA_BOOLEAN_FIELD,
|
||||
Array: SCHEMA_ARRAY_FIELD,
|
||||
Object: SCHEMA_OBJECT_FIELD,
|
||||
Date: SCHEMA_DATE_FIELD,
|
||||
File: SCHEMA_FILE_FIELD,
|
||||
GeoPoint: SCHEMA_GEO_POINT_FIELD,
|
||||
Polygon: SCHEMA_POLYGON_FIELD,
|
||||
Bytes: SCHEMA_BYTES_FIELD,
|
||||
Pointer: SCHEMA_POINTER_FIELD,
|
||||
Relation: SCHEMA_RELATION_FIELD,
|
||||
ACL: SCHEMA_ACL_FIELD,
|
||||
String: SCHEMA_STRING_FIELD.name,
|
||||
Number: SCHEMA_NUMBER_FIELD.name,
|
||||
Boolean: SCHEMA_BOOLEAN_FIELD.name,
|
||||
Array: SCHEMA_ARRAY_FIELD.name,
|
||||
Object: SCHEMA_OBJECT_FIELD.name,
|
||||
Date: SCHEMA_DATE_FIELD.name,
|
||||
File: SCHEMA_FILE_FIELD.name,
|
||||
GeoPoint: SCHEMA_GEO_POINT_FIELD.name,
|
||||
Polygon: SCHEMA_POLYGON_FIELD.name,
|
||||
Bytes: SCHEMA_BYTES_FIELD.name,
|
||||
Pointer: SCHEMA_POINTER_FIELD.name,
|
||||
Relation: SCHEMA_RELATION_FIELD.name,
|
||||
ACL: SCHEMA_ACL_FIELD.name,
|
||||
}[value.type]),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user