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.

@GraphQLContext for @GraphQLMutation to modify input type

See original GitHub issue

Hello!

I am trying to change the input type for a mutation, specifically for to-one relationships in our database.

So we have a business (has all the business specific info) that has a to-one relationship to the contact (has all the contact information) table.

I tried doing the following:

public Contact saveContact(
    @GraphQLContext
    Business business
) {
    // Create/update Contact information HERE
    return contactRepository.findById(business.getContactId()).block();
}

But do not see the input type modified at all.

Is this supported? What is the correct way to do this?

We are using SPQR version 0.10.1.

Thanks!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
kvakoscommented, Jun 2, 2020

In GraphQL you can have mutation structure equal to query structure. it brings unified graph for example

type Query {
  book(id: String): Book
}
type Book {
  name: String
  notes: [Note!]
}

and if you want to create mutation add note you can do it like

type Mutation {
  book(id: String) : BookOps
}
type BookOps {
  addNote(note : String) : NoteOps
}
type NoteOps {
  noteId: String
  note: String
  createdBy: String
}

Question is how to implement book.addNote mutation with spqr library. Any clue?

0reactions
kaqqaocommented, Mar 18, 2021

@meddox There’s no such thing as a nested mutation in GraphQL. You can read the spec for the details.

6.3.1 Normal and Serial Execution:

the resolution of fields other than top‐level mutation fields must always be side effect‐free and idempotent

I’ve also posted an explanation with references to the relevant spec articles in this Reddit thread. See my long comments, they go into the details and examples.

It comes down to asking if GET is the same as POST just without a body, why not write to the DB on a GET request?. You can. But it’s something that the tooling you use wasn’t made for.

Read more comments on GitHub >

github_iconTop Results From Across the Web

3. Adding mutations to your API - GraphQL Nexus
In this chapter you're going to add some write capability to your API. You'll learn about: Writing GraphQL mutations; Exposing GraphQL objects for...
Read more >
GraphQL SPQR extend mutation parameters of an input object
I came up with a way you can do this currently, but it requires some effort. I'm using GraphQL-SPQR 0.9.8 (that I'll release...
Read more >
GraphQL Mutation & Subscription - JavaScript in Plain English
For this example, I have modified the code and used the GraphQL context to pass the static list of data(db), used an input...
Read more >
Passing GraphQL Variables in Queries - react - Hasura
... of passing variables in GraphQL context and usage of Apollo GraphQL Mutation ... todos table with the $objects variable being passed as...
Read more >
GraphQL API style guide - GitLab Docs
Our GraphQL mutation names are historically inconsistent, but new mutation names should follow the ... graphql-ruby wraps up arguments into an input type....
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