feat: alphabetical graphql api, fix internal reassign, enhanced Graphql schema cache system (#7344)
This commit is contained in:
@@ -25,6 +25,7 @@ const {
|
||||
GraphQLEnumType,
|
||||
GraphQLInputObjectType,
|
||||
GraphQLSchema,
|
||||
GraphQLList,
|
||||
} = require('graphql');
|
||||
const { ParseServer } = require('../');
|
||||
const { ParseGraphQLServer } = require('../lib/GraphQL/ParseGraphQLServer');
|
||||
@@ -10341,6 +10342,18 @@ describe('ParseGraphQLServer', () => {
|
||||
robot: { value: 'robot' },
|
||||
},
|
||||
});
|
||||
const TypeEnumWhereInput = new GraphQLInputObjectType({
|
||||
name: 'TypeEnumWhereInput',
|
||||
fields: {
|
||||
equalTo: { type: TypeEnum },
|
||||
},
|
||||
});
|
||||
const SomeClass2WhereInput = new GraphQLInputObjectType({
|
||||
name: 'SomeClass2WhereInput',
|
||||
fields: {
|
||||
type: { type: TypeEnumWhereInput },
|
||||
},
|
||||
});
|
||||
const SomeClassType = new GraphQLObjectType({
|
||||
name: 'SomeClass',
|
||||
fields: {
|
||||
@@ -10386,6 +10399,18 @@ describe('ParseGraphQLServer', () => {
|
||||
return obj.toJSON();
|
||||
},
|
||||
},
|
||||
customQueryWithAutoTypeReturnList: {
|
||||
type: new GraphQLList(SomeClassType),
|
||||
args: {
|
||||
id: { type: new GraphQLNonNull(GraphQLString) },
|
||||
},
|
||||
resolve: async (p, { id }) => {
|
||||
const obj = new Parse.Object('SomeClass');
|
||||
obj.id = id;
|
||||
await obj.fetch();
|
||||
return [obj.toJSON(), obj.toJSON(), obj.toJSON()];
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
types: [
|
||||
@@ -10401,7 +10426,17 @@ describe('ParseGraphQLServer', () => {
|
||||
type: { type: TypeEnum },
|
||||
},
|
||||
}),
|
||||
// Enhanced where input with a extended enum
|
||||
new GraphQLInputObjectType({
|
||||
name: 'SomeClassWhereInput',
|
||||
fields: {
|
||||
type: {
|
||||
type: TypeEnumWhereInput,
|
||||
},
|
||||
},
|
||||
}),
|
||||
SomeClassType,
|
||||
SomeClass2WhereInput,
|
||||
],
|
||||
}),
|
||||
});
|
||||
@@ -10463,6 +10498,65 @@ describe('ParseGraphQLServer', () => {
|
||||
expect(result.data.customQueryWithAutoTypeReturn.type).toEqual('robot');
|
||||
});
|
||||
|
||||
it('can resolve a custom query with auto type list return', async () => {
|
||||
const obj = new Parse.Object('SomeClass');
|
||||
await obj.save({ name: 'aname', type: 'robot' });
|
||||
await parseGraphQLServer.parseGraphQLSchema.schemaCache.clear();
|
||||
const result = await apolloClient.query({
|
||||
variables: { id: obj.id },
|
||||
query: gql`
|
||||
query CustomQuery($id: String!) {
|
||||
customQueryWithAutoTypeReturnList(id: $id) {
|
||||
id
|
||||
objectId
|
||||
nameUpperCase
|
||||
name
|
||||
type
|
||||
}
|
||||
}
|
||||
`,
|
||||
});
|
||||
result.data.customQueryWithAutoTypeReturnList.forEach(rObj => {
|
||||
expect(rObj.objectId).toBeDefined();
|
||||
expect(rObj.objectId).toEqual(obj.id);
|
||||
expect(rObj.name).toEqual('aname');
|
||||
expect(rObj.nameUpperCase).toEqual('ANAME');
|
||||
expect(rObj.type).toEqual('robot');
|
||||
});
|
||||
});
|
||||
|
||||
it('can resolve a stacked query with same where variables on overloaded where input', async () => {
|
||||
const objPointer = new Parse.Object('SomeClass2');
|
||||
await objPointer.save({ name: 'aname', type: 'robot' });
|
||||
const obj = new Parse.Object('SomeClass');
|
||||
await obj.save({ name: 'aname', type: 'robot', pointer: objPointer });
|
||||
await parseGraphQLServer.parseGraphQLSchema.schemaCache.clear();
|
||||
const result = await apolloClient.query({
|
||||
variables: { where: { OR: [{ pointer: { have: { objectId: { exists: true } } } }] } },
|
||||
query: gql`
|
||||
query someQuery($where: SomeClassWhereInput!) {
|
||||
q1: someClasses(where: $where) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
q2: someClasses(where: $where) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
});
|
||||
expect(result.data.q1.edges.length).toEqual(1);
|
||||
expect(result.data.q2.edges.length).toEqual(1);
|
||||
expect(result.data.q1.edges[0].node.id).toEqual(result.data.q2.edges[0].node.id);
|
||||
});
|
||||
|
||||
it('can resolve a custom extend type', async () => {
|
||||
const obj = new Parse.Object('SomeClass');
|
||||
await obj.save({ name: 'aname', type: 'robot' });
|
||||
|
||||
Reference in New Issue
Block a user