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

Your schema defines a mutation field newItem that takes 3 arguments, but mutation fields must have exactly one argument named input. #663

Closed
jaredonline opened this issue Dec 7, 2015 · 8 comments

Comments

@jaredonline
Copy link

I'm not sure what's goin' on here. I've seen a lot of examples in the wild that take multiple arguments for a mutation.

The introspection looks like:
Query:

query schema {
  __schema{
    mutationType{
      name,
      fields{
        name,
        args{
          name,
          type{
            kind,
            ofType{
               kind,
               name
}}}}}}}

Response

{
  "data": {
    "__schema": {
      "mutationType": {
        "fields": [
          {
            "args": [
              {
                "name": "name",
                "type": {
                  "kind": "NON_NULL",
                  "ofType": {
                    "kind": "SCALAR",
                    "name": "String"
                  }
                }
              },
              {
                "name": "purchase_price_cents",
                "type": {
                  "kind": "NON_NULL",
                  "ofType": {
                    "kind": "SCALAR",
                    "name": "Int"
                  }
                }
              },
              {
                "name": "sale_price_cents",
                "type": {
                  "kind": "NON_NULL",
                  "ofType": {
                    "kind": "SCALAR",
                    "name": "Int"
                  }
                }
              }
            ],
            "name": "newItem"
          }
        ],
        "name": "Mutation"
      }
    }
  }
}

Is this actually a problem with my schema or something else?

@josephsavona
Copy link
Contributor

See the Relay Mutation Spec.

@josephsavona
Copy link
Contributor

Relay requires that GraphQL schema follow a few conventions - single arguments to mutations is one of them.

@jaredonline
Copy link
Author

Aha, I see. Thanks for the super fast response! I was looking at this mutations guide which seems to be a bit out of date? It doesn't mention the special "input" variable anywhere ]=

@josephsavona
Copy link
Contributor

@jaredonline Yeah, that guide is meant to cover mutations on the Relay side, but we should probably link to the Mutations Spec from that guide. PRs welcome! ;-)

@Ansalibrahim
Copy link

Ansalibrahim commented Nov 17, 2016

@jaredonline

single arguments to mutations is one of them.

Is there any chance to pass multiple arguments to mutations? I have seen some code like this somewhere
getVariables() { return { text: this.props.text, id:this.props.id, time:this.props.time }; }

@Naoto-Ida
Copy link

Naoto-Ida commented Nov 22, 2016

@Ansalibrahim I have the same problem too.

The document states that:

Implement this required method to prepare variables to be used as input to the mutation.

so I assumed we can pass multiple arguments when doing mutations.

I'm getting the same mutation fields must have exactly one argument named 'input' when I do the following:

getVariables() {
  return {
    name: this.props.name,
    type: this.props.type,
  }
}

I checked out my schema.js just to make sure an input argument wasn't automatically added, but seems like thats not the case. I can also successfully do the same mutation from GraphiQL.

So this could be something in react-relay or babel-relay-plugin?

!UPDATE!

After looking through more recent issues, it seems that it is true that input is required.

So on the GraphQL side I wrapped all my previous args in a field called input with the type GraphQLInputObjectType. Problem solved. But I think the documentation needs clarification on this.

@josephsavona
Copy link
Contributor

@Naoto-Ida Glad you got this solved. We've documented this requirement in the Relay Mutation Spec, but if there are other places that you expected to see it and didn't, please submit a PR to update the docs!

@Naoto-Ida
Copy link

@josephsavona Ok, thank you for pointing that out. I'll see if I can submit a PR this week.

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

No branches or pull requests

4 participants