question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

updateOrCreate not possible with apollo-client

See original GitHub issue

Graphcool added an updateOrCreate method https://www.graph.cool/forum/t/input-type-mutations-in-graphcool/726/4. The $id is not provided if its a new record. However, I’m not able to provide an optional $id because I get an error ID and ID! are not compatible.

Intended outcome:

mutation UpdateItem(
  $id: ID,
  $name: String!,
){
  updateOrCreateItem(
    update: {
      id: $id,
      name: $name
    }
    create: {
      name: $name
    }
  ){
    id
  }
}

Actual outcome:

Save Options Error: GraphQL error: Variable '$id' expected value of type 'ID!' but value is undefined...

Version “apollo-client-preset”: “^1.0.5”, “apollo-codegen”: “^0.18.3”, “apollo-link-context”: “^1.0.3”, “react-apollo”: “^2.0.4”,

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
n1ru4lcommented, Jan 12, 2018

That is right because apollo-client checks if a param that is marked as required is provided.

0reactions
hwillsoncommented, Jun 1, 2018

As mentioned in https://github.com/apollographql/apollo-client/issues/2861#issuecomment-357179901, this is not an apollo-client error. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading and writing data to the cache - Apollo GraphQL Docs
You can read and write data directly to the Apollo Client cache, without communicating with your GraphQL server. You can interact with data...
Read more >
Create or Update 1:1 record on Dynamo DB related to Cognito ...
I've got troubles on trying either of two. userSub cannot be primary key. Is there any way to update (or create if not...
Read more >
Vue GraphQL integration using Apollo Client - End Point Dev
With these you'll be able to: Manually run GraphQL queries and mutations from any Vue component via the this.$apollo helper; Automatically map ...
Read more >
client-preset - GraphQL Code Generator
@apollo/client (since 3.2.0 , not when using React Components ... namingConvention : Available case functions in change-case-all are ...
Read more >
Using GraphQL to perform queries - Jahia Academy
In addition, some graphQL fields may or may not be allowed for a user. ... Mutations are provided to update or create nodes....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found