Relay Spec (#6089)

* Install graphql-relay

* Add relayNodeInterface to ParseGraphQLSchema

* Add support to global id

* Add support to global id in other operations

* Fix sort by glboal id

* Fix where by global id

* Introduce IdWhereInput

* Add Relay object identification tests

* Client mutation id on createFile mutation

* Client mutation id on callCloudCode mutation

* Client mutation id on signUp mutation

* Client mutation id on logIn mutation

* Client mutation id on logOut mutation

* Client mutation id on createClass mutation

* Client mutation id on updateClass mutation

* Client mutation id on deleteClass mutation

* Client mutation id on create object mutation

* Improve Viewer type

* Client mutation id on update object mutation

* Client mutation id on delete object mutation

* Introducing connections

* Fix tests

* Add pagination test

* Fix file location

* Fix postgres tests

* Add comments

* Tests to calculateSkipAndLimit
This commit is contained in:
Antonio Davi Macedo Coelho de Castro
2019-12-01 21:43:08 -08:00
committed by GitHub
parent 67e3c33ffe
commit a9066e20dc
22 changed files with 4685 additions and 2816 deletions

View File

@@ -1,5 +1,10 @@
import Parse from 'parse/node';
import { GraphQLSchema, GraphQLObjectType } from 'graphql';
import {
GraphQLSchema,
GraphQLObjectType,
DocumentNode,
GraphQLNamedType,
} from 'graphql';
import { mergeSchemas, SchemaDirectiveVisitor } from 'graphql-tools';
import requiredParameter from '../requiredParameter';
import * as defaultGraphQLTypes from './loaders/defaultGraphQLTypes';
@@ -16,6 +21,7 @@ import { toGraphQLError } from './parseGraphQLUtils';
import * as schemaDirectives from './loaders/schemaDirectives';
import * as schemaTypes from './loaders/schemaTypes';
import { getFunctionNames } from '../triggers';
import * as defaultRelaySchema from './loaders/defaultRelaySchema';
const RESERVED_GRAPHQL_TYPE_NAMES = [
'String',
@@ -27,10 +33,25 @@ const RESERVED_GRAPHQL_TYPE_NAMES = [
'Query',
'Mutation',
'Subscription',
'CreateFileInput',
'CreateFilePayload',
'Viewer',
'SignUpFieldsInput',
'LogInFieldsInput',
'SignUpInput',
'SignUpPayload',
'LogInInput',
'LogInPayload',
'LogOutInput',
'LogOutPayload',
'CloudCodeFunction',
'CallCloudCodeInput',
'CallCloudCodePayload',
'CreateClassInput',
'CreateClassPayload',
'UpdateClassInput',
'UpdateClassPayload',
'DeleteClassInput',
'DeleteClassPayload',
'PageInfo',
];
const RESERVED_GRAPHQL_QUERY_NAMES = ['health', 'viewer', 'class', 'classes'];
const RESERVED_GRAPHQL_MUTATION_NAMES = [
@@ -48,7 +69,14 @@ class ParseGraphQLSchema {
databaseController: DatabaseController;
parseGraphQLController: ParseGraphQLController;
parseGraphQLConfig: ParseGraphQLConfig;
graphQLCustomTypeDefs: any;
log: any;
appId: string;
graphQLCustomTypeDefs: ?(
| string
| GraphQLSchema
| DocumentNode
| GraphQLNamedType[]
);
constructor(
params: {
@@ -56,6 +84,12 @@ class ParseGraphQLSchema {
parseGraphQLController: ParseGraphQLController,
log: any,
appId: string,
graphQLCustomTypeDefs: ?(
| string
| GraphQLSchema
| DocumentNode
| GraphQLNamedType[]
),
} = {}
) {
this.parseGraphQLController =
@@ -105,8 +139,10 @@ class ParseGraphQLSchema {
this.graphQLSubscriptions = {};
this.graphQLSchemaDirectivesDefinitions = null;
this.graphQLSchemaDirectives = {};
this.relayNodeInterface = null;
defaultGraphQLTypes.load(this);
defaultRelaySchema.load(this);
schemaTypes.load(this);
this._getParseClassesWithConfig(parseClasses, parseGraphQLConfig).forEach(
@@ -208,10 +244,16 @@ class ParseGraphQLSchema {
return this.graphQLSchema;
}
addGraphQLType(type, throwError = false, ignoreReserved = false) {
addGraphQLType(
type,
throwError = false,
ignoreReserved = false,
ignoreConnection = false
) {
if (
(!ignoreReserved && RESERVED_GRAPHQL_TYPE_NAMES.includes(type.name)) ||
this.graphQLTypes.find(existingType => existingType.name === type.name)
this.graphQLTypes.find(existingType => existingType.name === type.name) ||
(!ignoreConnection && type.name.endsWith('Connection'))
) {
const message = `Type ${type.name} could not be added to the auto schema because it collided with an existing type.`;
if (throwError) {