Skip to main content

Client library for making graphql calls

Project description

codecov

A pythonic interface for making requests to a GraphQL server using pydantic models to spare you from string manipulation.

Features

  • Use pydantic BaseModel to specify graphql parameters and responses

  • Create and execute GraphQL Queries based upon typed models

  • Create and execute GraphQL Mutations based upon typed models

  • Async support

Installation

pip install gqlclient

with asyncio support

pip install gqlclient[async]

Examples

Query

from pydantic import BaseModel

from gqlclient import GraphQLClient


class Parameters(BaseModel):
    attr_one: str
    attr_two: int


class Response(BaseModel):
    attr_three: int
    attr_four: str

client = GraphQLClient(gql_uri="http://localhost:5000/graphql")
parameters = Parameters(attr_one="foo", attr_two=3)
query = client.get_query(query_base="baseType", query_response_cls=Response, query_parameters=parameters)
print(query)
#{'query': '{baseType(attr_one: "foo", attr_two: 3){attr_three, attr_four} }'}
response = client.execute_gql_query(query_base="baseType", query_response_cls=Response, query_parameters=parameters)
print(response)
#{"data": "baseType"{"attr_three":5, "attr_four":"bar"}}

Mutation

from pydantic import BaseModel

from gqlclient import GraphQLClient


class Parameters(BaseModel):
    attr_one: str
    attr_two: int


class Response(BaseModel):
    attr_three: int
    attr_four: str

client = GraphQLClient(gql_uri="http://localhost:5000/graphql")
parameters = Parameters(attr_one="foo", attr_two=3)
query = client.get_mutation(mutation_base="baseMutation", mutation_response_cls=Response, mutation_parameters=parameters)
print(query)
#{'query': 'mutation baseType {baseType(attr_one: "foo", attr_two: 3){ok, attr_three, attr_four} }', 'operationName': 'baseType'}

response = client.execute_gql_mutation(mutation_base="baseMutation", mutation_response_cls=Response, mutation_parameters=parameters)
print(response)
#{"data": {"baseMutation": {"ok": true, "Response": {"attr_three":5, "attr_four":"bar"} }}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gqlclient-0.1.1rc4.tar.gz (8.3 kB view details)

Uploaded Source

File details

Details for the file gqlclient-0.1.1rc4.tar.gz.

File metadata

  • Download URL: gqlclient-0.1.1rc4.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3

File hashes

Hashes for gqlclient-0.1.1rc4.tar.gz
Algorithm Hash digest
SHA256 cb99b6e0afd26f9dbac6a8be60bb25cc72a83233b9ba0217bd42e96f62e2550d
MD5 c2bc20410ea24e5273feeec608fbfc38
BLAKE2b-256 662e30ce421d6d0d30021bc7e3176e5f5671869132dff2114efbd86b1fcda2a2

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page