const outdentDlItem = (editor: Editor, item: Element): void => { if (Compare.is(item, 'dd')) { Replication.mutate(item, 'dt'); } else if (Compare.is(item, 'dt')) { Traverse.parent(item).each((dl) => SplitList.splitList(editor, dl.dom(), item.dom())); } }
const normalizeSegment = (segment: Segment, entry: Entry): void => { if (Node.name(segment.list) !== entry.listType) { segment.list = Replication.mutate(segment.list, entry.listType); } Attr.setAll(segment.list, entry.listAttributes); }
graphql(createUserGql, { props: ({ mutate }) => ({ mutations: { signUp: ({ firstName, lastName, email, password }) => mutate({ variables: { firstName, lastName, email, password } }) } }) })
it('can throw errors', async () => { Parse.Cloud.define('hello', async () => { throw new Error('Some error message.'); }); try { await apolloClient.mutate({ mutation: gql` mutation CallFunction { callCloudCode(input: { functionName: hello }) { result } } `, }); fail('Should throw an error'); } catch (e) { const { graphQLErrors } = e; expect(graphQLErrors.length).toBe(1); expect(graphQLErrors[0].message).toBe('Some error message.'); } });
async function updateObject(className, id, fields, headers) { return await apolloClient.mutate({ mutation: gql` mutation UpdateSomeObject( $id: ID! $fields: Update${className}FieldsInput ) { update: update${className}(input: { id: $id fields: $fields clientMutationId: "someid" }) { clientMutationId } } `, variables: { id, fields, }, context: { headers, }, }); }
function deleteObject(className, id, headers) { const mutationName = className.charAt(0).toLowerCase() + className.slice(1); return apolloClient.mutate({ mutation: gql` mutation DeleteSomeObject( $id: ID! ) { delete: delete${className}(input: { id: $id }) { ${mutationName} { objectId } } } `, variables: { id, }, context: { headers, }, }); }
it('should require master key to create a new class', async () => { try { await apolloClient.mutate({ mutation: gql` mutation { createClass(input: { name: "SomeClass" }) { clientMutationId } } `, }); fail('should fail'); } catch (e) { expect(e.graphQLErrors[0].extensions.code).toEqual( Parse.Error.OPERATION_FORBIDDEN ); expect(e.graphQLErrors[0].message).toEqual( 'unauthorized: master key is required' ); } });
it('should support createdAt and updatedAt', async () => { await apolloClient.mutate({ mutation: gql` mutation CreateClass { createClass(input: { name: "SomeClass" }) { clientMutationId } } `, context: { headers: { 'X-Parse-Master-Key': 'test', }, }, }); const schema = await new Parse.Schema('SomeClass').get(); expect(schema.fields.createdAt.type).toEqual('Date'); expect(schema.fields.updatedAt.type).toEqual('Date'); });
graphql(createPostGql, { props: ({ mutate }) => ({ mutations: { createPost: (title, url) => mutate({ variables: { title, url }, updateQueries: { allPosts: (previousResult, { mutationResult }) => { const newPost = mutationResult.data.createPost; return Object.assign({}, previousResult, { // Append the new post allPosts: [newPost, ...previousResult.allPosts] }); } } }) } }) })
const indentDlItem = (item: Element): void => { if (Compare.is(item, 'dt')) { Replication.mutate(item, 'dd'); } }
graphql(upvotePostGql, { props: ({ ownProps, mutate }) => ({ upvote: (id, votes) => mutate({ variables: { id, votes }, optimisticResponse: { __typename: 'Mutation', updatePost: { __typename: 'Post', id: ownProps.id, votes: ownProps.votes + 1 } } }) }) })
it('should fail if deleting an inexistent class', async () => { try { await apolloClient.mutate({ mutation: gql` mutation { deleteClass(input: { name: "SomeInexistentClass" }) { clientMutationId } } `, context: { headers: { 'X-Parse-Master-Key': 'test', }, }, }); fail('should fail'); } catch (e) { expect(e.graphQLErrors[0].extensions.code).toEqual( Parse.Error.INVALID_CLASS_NAME ); expect(e.graphQLErrors[0].message).toEqual( 'Class SomeInexistentClass does not exist.' ); } });
graphql(signInGql, { props: ({ mutate }) => ({ mutations: { signIn: ({ email, password }) => mutate({ variables: { email, password } }) } }) })
function deleteObject(className, id, headers) { const mutationName = className.charAt(0).toLowerCase() + className.slice(1); return apolloClient.mutate({ mutation: gql` mutation DeleteSomeObject( $id: ID! ) { delete${className}(input: { id: $id }) { ${mutationName} { objectId } } } `, variables: { id, }, context: { headers, }, }); }
function updateObject(className, id, fields, headers) { const mutationName = className.charAt(0).toLowerCase() + className.slice(1); return apolloClient.mutate({ mutation: gql` mutation UpdateSomeObject( $id: ID! $fields: Update${className}FieldsInput ) { update${className}(input: { id: $id fields: $fields }) { ${mutationName} { updatedAt } } } `, variables: { id, fields, }, context: { headers, }, }); }