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 error when not passing value for optional variables #144

Closed
MichaelDeBoey opened this issue May 11, 2017 · 3 comments
Closed

GraphQL error when not passing value for optional variables #144

MichaelDeBoey opened this issue May 11, 2017 · 3 comments

Comments

@MichaelDeBoey
Copy link

On updating to the newest release, we started getting errors when not passing a value for optional variables

schema:

type Query {
  Files(linked_id: LinkedId!, map_id: Int): File
}

type File {
  id: Int
  name: String
  added_time: String
}

type LinkedId {
  contract_id: Int
  object_id: Int
}

query:

query getAllFilesForFolderQuery($linkedId: LinkedId!, $folderId: Int) {
  files: Files(linked_id: $linkedId, map_id: $folderId) {
    id
    name
    addedOn: added_time
  }
}

variables:

{
  linkedId: {contract_id: 4394885}
}

response:

{"errors": [
    {"message": "Variable folderId hasn't been submitted"}
]}
@viniychuk
Copy link
Member

@MichaelDeBoey it was actually a flaw in the library... there's not such thing as "optional variable" in the GraphQL protocol... we'll try to reproduce it in the JS version, but according to https://facebook.github.io/graphql/#sec-Coercing-Field-Arguments (http://take.ms/dAxN1) it's not clear. You can join conversation on gitter, we're just discussing it https://gitter.im/Youshido/GraphQL

@fritz-gerneth
Copy link
Contributor

As @viniychuk mentioned, variables don't have default values by themselves - you have to provide a default value for that variable (copied example from here):

query ($username: String = "GovSchwarzenegger"){
  reddit {
    user(username: $username) {
      username
      commentKarma
      createdISO
    }
  }
}

Unfortunately as it seems, the library cannot parse this yet. At least when I do this on a query, I do get a parse error:

{
  "errors": [
    {
      "message": "Can\\t recognize token type",
      "locations": [
        {
          "line": 1,
          "column": 25
        }
      ]
    }
  ]
}

which corresponds to the whitespace after the variable's type.

@viniychuk
Copy link
Member

fixed in 1.4.3.4

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

3 participants