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

Include optional parameter in the variables field of a request when the parameter value is null #6681

Closed
CalvinQuark opened this issue Nov 7, 2023 · 2 comments · Fixed by #6689

Comments

@CalvinQuark
Copy link

Product

Strawberry Shake

Is your feature request related to a problem?

There is a compatibility issue when using a ChilliCream StrawberryShake generated client to fetch data from an Azure Data API Builder CLI-generated GraphQL endpoint.

If a query is defined with an optional $filter parameter such as:

query Todos(
  $filter: TodoFilterInput
) {
  todos(
    filter: $filter
  ) {
    items {
      Id
      Title
      DueOn
    }
  }
}

When a null value is passed to filter parameter via a ChilliCream StrawberryShake-generated client query's .ExecuteAsync(filter: null) method, the request does not include the "filter": null node in the variables section:

{
    "id": "ec304833fcb193a31fdd994a6c503e21",
    "query": "query Todos($filter: TodoFilterInput) { todos(filter: $filter) { __typename items { __typename Id Title DueOn } } }",
    "operationName": "Todos",
    "variables": {}
}

Unfortunately, the Azure Data API Builder CLI's GraphQL endpoint responds to this request with:

{
  "errors": [
    {
      "message": "The variable with the name `filter` does not exist."
    }
  ]
}

unless the null-valued filter variable is specifically included in the request payload. I.e., this works:

{
    "id": "ec304833fcb193a31fdd994a6c503e21",
    "query": "query Todos($filter: TodoFilterInput) { todos(filter: $filter) { __typename items { __typename Id Title DueOn } } }",
    "operationName": "Todos",
    "variables": {
        "filter": null
    }
}

I haven't discovered a workaround for this issue either on the client side with StrawberryShake or on the server side with Azure Data API Builder. Is there a way to coax the StrawberryShake-generated Client to include the unused null filter variable?

The solution you'd like

OOB compatibility between ChilliCream StrawberryShake generated clients and Azure Data API Builder CLI-generated GraphQL endpoints.

@CalvinQuark
Copy link
Author

JSON serialization stripping out null properties seems to be the root cause.

@CalvinQuark
Copy link
Author

According to ChatGPT-4, in GraphQL if an argument is optional, "the client should not be required to include it in the query". If so, then this is an issue for the Azure Data API Builder team rather than for the ChilliCream/StrawberryShake team. Consequently, I have posted the issue there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants