Azure / Azure/data-api-builder

Omit optional parameter in the variables field of a request when the parameter value is null

Aperta
#1,871 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C#
Stelle
1.5k
Fork
370
Merge medio
3g 17h
PR unite (30g)
8

Descrizione

I posted this originally in _Discussions_ ~ _Ideas_. However, it now seems worthy to be promoted to an _Issue_. According to ChatGPT-4, the behavior of the server (at least as hosted by the DAB CLI -- I haven't tested it when deployed to Azure SWA) [is not compliant with the GraphQL spec.](https://github.com/Azure/data-api-builder/discussions/1867#discussioncomment-7509762). After having subsequently perused the Data API Builder's source code, I see that it uses ChilliCream's server libraries extensively. Therefore, also it seems like an issue that ChilliCream's StawberryClient null-parameter handling differs from the expectation of the server.

### Discussed in https://github.com/Azure/data-api-builder/discussions/1867

Originally posted by **CalvinQuark** November 7, 2023
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:

```gql
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:

```json
{
"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:

```json
{
"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:

```json
{
"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 particular reason why it is necessary to include the unused null `filter` variable? If so, this seems unintuitive since the query parameter is declared as nullable `$filter: TodoFilterInput`. I.e., it's not suffixed with the required operator (`!`).

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia riproducendo la richiesta sull’endpoint GraphQL di Azure Data API Builder CLI, usando la variabile opzionale $filter e i due payload delle variabili mostrati nell’issue. Leggi la Discussion #1867 correlata e analizza l’integrazione della server-library ChilliCream menzionata lì. Il lavoro è completato quando la richiesta con la variabile nullable viene gestita in modo coerente senza l’errore segnalato di variabile mancante.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp, graphql
Ambito
api, backend-api-design
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.