Welcome to gqlclient documentation!

Implementation of the Base graphql client to support the synchronous creation and execution of graphql queries and mutations

class client.GraphQLClient(gql_uri: str, default_response_encoder: Optional[Callable[[str, dict, type], Any]] = <function dataclass_encoder>)[source]

Helper class for formatting and executing synchronous GraphQL queries and mutations

execute_gql_call(query: dict, **kwargs) → dict[source]

Executes a GraphQL query or mutation using requests.

Parameters:
  • query – Dictionary formatted graphql query
  • kwargs – Optional arguments that requests takes. e.g. headers
Returns:

Dictionary containing the response from the GraphQL endpoint

Base class to support the creation of graphql queries and mutations.

class base.GraphQLClientBase(gql_uri: str, default_response_encoder: Optional[Callable[[str, dict, type], Any]] = <function dataclass_encoder>)[source]

Abstract class for formatting and executing GraphQL queries and mutations

Parameters:gql_uri – Fully qualified URI for the graphQL endpoint.
execute_gql_call(query: dict, **kwargs) → dict[source]

Executes a GraphQL query or mutation.

Parameters:
  • query – Dictionary formatted graphql query
  • kwargs – Optional arguments that the http client takes. e.g. headers
Returns:

Dictionary containing the response from the GraphQL endpoint

execute_gql_mutation(mutation_base: str, mutation_parameters: object, mutation_response_cls: Optional[type] = None, response_encoder: Optional[Callable[[str, Union[List[dict], dict], type], Any]] = None, **kwargs) → Any[source]

Executes a graphql mutation based upon input dataclass models.

Parameters:
  • mutation_base – Name of the root type to be mutated
  • mutation_parameters – Instance of a dataclass model containing attributes corresponding to

parameter names and values corresponding to the parameter value.

Parameters:mutation_response_cls – Optional. A dataclass model class representing the structure of the

response object with attributes corresponding to the Graphql type and attribute names.

Parameters:
  • response_encoder – A callable which takes the following arguments: str for the base type call e.g. query_base or mutation_base dict for the data returned in under the ‘data’ key type for the dataclass that structured the response
  • kwargs – Optional arguments that http client (requests) takes. e.g. headers
Returns:

The response formatted by the specified response_encoder. Default is dict if no encoder is specified

execute_gql_query(query_base: str, query_response_cls: type, query_parameters: Optional[object] = <class 'base.DefaultParameters'>, response_encoder: Optional[Callable[[str, Union[List[dict], dict], type], Any]] = None, **kwargs) → Any[source]

Executes a graphql query based upon input dataclass models.

Parameters:
  • query_base – Name of the root type to be queried
  • query_parameters – Optional. Instance of a dataclass model containing attributes corresponding to

parameter names and values corresponding to the parameter value.

Parameters:query_response_cls – A dataclass model class representing the structure of the response

object with attributes corresponding to the Graphql type and attribute names

Parameters:
  • response_encoder – A callable which takes a dict graphql response and returns a reformatted type
  • kwargs – Optional arguments that http client (requests) takes. e.g. headers
Returns:

The response formatted by the specified response_encoder. Default is dict if no encoder is specified

get_mutation(mutation_base: str, mutation_parameters: object, mutation_response_cls: Optional[type] = None) → Dict[str, str][source]

Create a GraphQL formatted mutation string.

Parameters:
  • mutation_base – Name of the root type to be mutated
  • mutation_parameters – Instance of a dataclass model containing attributes corresponding to

parameter names and values corresponding to the parameter value. :param mutation_response_cls: Optional. A dataclass model class representing the structure of the response object with attributes corresponding to the Graphql type and attribute names.

Returns:Dictionary that can be passed as json to the GraphQL API endpoint
get_query(query_base: str, query_response_cls: type, query_parameters: Optional[object] = <class 'base.DefaultParameters'>) → Dict[str, str][source]

Create a GraphQL formatted query string.

Parameters:
  • query_base – Name of the root type to be queried
  • query_response_cls – A dataclass model class representing the structure of the response object

with attributes corresponding to the Graphql type and attribute names :param query_parameters: Optional. Instance of a dataclass model containing attributes corresponding to parameter names and values corresponding to the parameter value.

Returns:Dictionary that can be passed as json to the GraphQL API endpoint

Indices and tables