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

Improve GraphQL Variable Validation #4206

Closed
ThisaruGuruge opened this issue Mar 15, 2023 · 0 comments · Fixed by ballerina-platform/module-ballerina-graphql#1297
Closed
Assignees
Labels
module/graphql Issues related to Ballerina GraphQL module Team/PCM Protocol connector packages related issues Type/Improvement

Comments

@ThisaruGuruge
Copy link
Member

ThisaruGuruge commented Mar 15, 2023

Description:
When a document contains more than one operation with variables, variable validation throws an error for not providing variable values for unused variables.

Consider the following schema:

type Query {
  messages: [Message!]
  message(id: Int!): Message
}

type Mutation {
  addMessage(input: MessageInput!): Message
}

type Message {
  id: Int!
  from: String!
  text: String!
}

input MessageInput {
  from: Int!
  text: String!
}

Send the following document to the above service with operationName: "SendMessage" :

query GetMessage($id: Int!) {
    message(id: $id) {
        from
        text
    }
}

mutation SendMessage($input: MessageInput!) {
    message: addMessage(input: $input) {
        from
    }
}

With the following variables map:

{
    "input": {
        "from": 1,
        "text": "Hi"
    }
}

This throws an error:

{
    "errors": [
        {
            "message": "Variable "$id" of required type Int! was not provided.",
            "locations": //...
         }
    ]
}

But this operation can be executed without the $id variable since it is not required for the operation.

IMO, after parsing, we should only validate the given operation from the document, and we can omit the validation of other opertations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/graphql Issues related to Ballerina GraphQL module Team/PCM Protocol connector packages related issues Type/Improvement
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants