Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL DX: Relation/Pointer #5946

Merged
merged 7 commits into from
Aug 21, 2019

Conversation

Moumouls
Copy link
Member

@Moumouls Moumouls commented Aug 19, 2019

#5863

  • Change DX for Relation
  • Change DX for Pointer
  • Add a deep GraphQL Query test

Relation

input RelationInput {
   objectId: ID!
}

input ExampleRelationInput {
  add: [RelationInput!]
  addAndCreate: [CreateExampleFieldsInput!]
  remove: [RelationInput!]
}

Pointer

input PointerInput {
   objectId: ID!
}

# You need to choose link OR addAndLink
input ExamplePointerInput {
  link: PointerInput
  addAndLink: [CreateExampleFieldsInput!]
}

@codecov
Copy link

codecov bot commented Aug 20, 2019

Codecov Report

Merging #5946 into master will decrease coverage by 0.08%.
The diff coverage is 93.4%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #5946      +/-   ##
=========================================
- Coverage   93.68%   93.6%   -0.09%     
=========================================
  Files         156     156              
  Lines       10850   10897      +47     
=========================================
+ Hits        10165   10200      +35     
- Misses        685     697      +12
Impacted Files Coverage Δ
src/GraphQL/loaders/objectsMutations.js 96.96% <ø> (-0.26%) ⬇️
src/GraphQL/parseGraphQLUtils.js 92.85% <100%> (+0.54%) ⬆️
src/GraphQL/loaders/parseClassTypes.js 85.59% <100%> (+0.25%) ⬆️
src/GraphQL/loaders/defaultGraphQLTypes.js 97.21% <100%> (+0.02%) ⬆️
src/GraphQL/loaders/parseClassMutations.js 93.42% <60%> (-4.29%) ⬇️
src/GraphQL/transformers/mutation.js 96.49% <96.49%> (-3.51%) ⬇️
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 92.23% <0%> (-0.71%) ⬇️
src/RestWrite.js 93.39% <0%> (-0.5%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fddd9c2...b09f69a. Read the comment docs.

@Moumouls Moumouls marked this pull request as ready for review August 20, 2019 18:35
@Moumouls
Copy link
Member Author

Moumouls commented Aug 20, 2019

createAndAdd and createAndLink support unlimited deep nested mutation ✊

Example

const {
  data: { createCountry: result },
} = await apolloClient.mutate({
  mutation: gql`
    mutation CreateCountry($fields: CreateCountryFieldsInput) {
      createCountry(fields: $fields) {
        objectId
        name
        companies {
          results {
            objectId
            name
            teams {
              results {
                objectId
                name
              }
            }
          }
        }
      }
    }
  `,
  variables: {
    fields: {
      name: 'imACountry2',
      companies: {
        createAndAdd: [
          {
            name: 'imACompany2',
            teams: {
              createAndAdd: {
                name: 'imATeam2',
              },
            },
          },
          {
            name: 'imACompany3',
            teams: {
              createAndAdd: {
                name: 'imATeam3',
              },
            },
          },
        ],
      },
    },
  },
});

@Moumouls
Copy link
Member Author

@davimacedo ready for review 👍

Copy link
Member

@davimacedo davimacedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks really good to me! I only left two small comments. @douglasmuraoka do you want to take a look as well?

src/GraphQL/loaders/parseClassMutations.js Outdated Show resolved Hide resolved
src/GraphQL/loaders/parseClassMutations.js Outdated Show resolved Hide resolved
Copy link
Member

@davimacedo davimacedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me. @douglasmuraoka can you please also take a look?

@douglasmuraoka
Copy link
Contributor

@Moumouls I've tried some operations, such as updating an object removing one element from the relation and linking a pointer, and I got the following error (although the operation worked):

Cannot return null for non-nullable field Foo.objectId.

Query:

mutation {
  updateFoo(objectId:"hShcOgTmIF" fields: {
    pointerrrr: {
      link: {
        objectId: "NCc4wLTr50"
      }
    }
  }) {
    objectId
  }
}

Could you please take a look?

@Moumouls
Copy link
Member Author

Moumouls commented Aug 21, 2019

@Moumouls I've tried some operations, such as updating an object removing one element from the relation and linking a pointer, and I got the following error (although the operation worked):

Cannot return null for non-nullable field Foo.objectId.

Query:

mutation {
  updateFoo(objectId:"hShcOgTmIF" fields: {
    pointerrrr: {
      link: {
        objectId: "NCc4wLTr50"
      }
    }
  }) {
    objectId
  }
}

Could you please take a look?

Strange, the test for should support pointer on update currently works...

The error appear on each operation ?

@douglasmuraoka
Copy link
Contributor

The test should support pointer on update works because it's fetching more than the objectId of the updated object. I've changed the mutation to the above and it failed:

mutation Update($objectId: ID! $fields: UpdateCountryFieldsInput)  {
    updateCountry(objectId: $objectId, fields: $fields) {
        objectId
    }
}

@Moumouls
Copy link
Member Author

Fixed, the issue was introduced in #5893
Thanks for the review @douglasmuraoka !

@davimacedo davimacedo merged commit 5b3a492 into parse-community:master Aug 21, 2019
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this pull request Mar 21, 2020
* Add a test on deep complex GraphQL Query

* Relation/Pointer new DX + deep nested mutations

* Fix lint

* Review

* Remove unnecessary code

* Fix objectId on update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants