Skip to content

Optional query arguments #360

@franden

Description

@franden

Ia m using the microprofile-graphql-client 1.1.0 in my quarkus project and I am struggling with an issue with optional parameter for some quieries.
The used GraphQL API allows to filter catalogue entries with a filter argument. If some filter attributes are applied, then the result is filtered, otherwise no filtering is done.

@Query("catalogues")
List<CatalogueDTO> getCatalogues(
    @Header(name = HttpHeaders.AUTHORIZATION) String authorization,
    @Header(name = "customer-id") String customerId,
    @Name("filter")CatalogueRequestParams catalogueRequestParams
);

@Input("CatalogueRequestParams")
public class CatalogueRequestParams {

    FrameType frameType;
    Boolean remoteEdgingEnabled;

    public Boolean getRemoteEdgingEnabled() {
        return remoteEdgingEnabled;
    }

    public CatalogueRequestParams setRemoteEdgingEnabled(Boolean remoteEdgingEnabled) {
        this.remoteEdgingEnabled = remoteEdgingEnabled;
        return this;
    }

    public FrameType getFrameType() {
        return frameType;
    }

    public CatalogueRequestParams setFrameType(FrameType frameType) {
        this.frameType = frameType;
        return this;
    }
}

A) If the filter parameter are set, this query will be generated:

{
	"query": "query catalogues($filter: CatalogueRequestParams) { catalogues(filter: $filter) {type owner uid} }",
	"variables": {
		"filter": {
                        "frameType": "METALL",
			"remoteEdgingEnabled": true
		}
	},
	"operationName": "catalogues"
}

B) if the parameter are not set, the filter will be set to null.

{
	"query": "query catalogues($filter: CatalogueRequestParams) { catalogues(filter: $filter) {type owner uid} }",
	"variables": {
		"filter": {
			"frameType": null,
			"remoteEdgingEnabled": null
		}
	},
	"operationName": "catalogues"
}

issue in case A) "remoteEdgingEnabled": true leads to an validation exception on the GraphQL server. if I change it to "remoteEdgingEnabled": "true" the query works.

issue in case B) leads to an validation exception on the GraphQL server. It works only if I remove the filter values completely.

My Questions:

  • Do I am facing an issue with the microprofile-graphql-client or is it a issue with the server implementation of the GraphQL API?
  • Can I somehow instrument microprofile-graphql-client to "ignore" variables which are set to null? Because in my case, absence of an filter has different meaning as set to null or false.
  • Why are the queries generated by microprofile-graphql-client are using "variables". Is it possible to instrument it to generate queries like this:
{
  catalogues(filter: {frameType: METAL  remoteEdgingEnabled:true} ) {
    type,
    owner,
    uid,
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions