📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

simple-graphql-client

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-graphql-client

A simple graphql client which also supports file upload

0.0.4
PyPI
Maintainers
1

Simple GraphQL Client

Installation

The client is available on PyPI:

  • $ pip install simple-graphql-client

Examples

Executing a query

from simple_graphql_client import GraphQLClient

headers = {'Authorization': 'Bearer ...'}

client = GraphQLClient("https://...", headers=headers)

query = "..."

variables = {
    ...
}
data = client.query(query=query, variables=variables)

Executing a query with a single file

Note: For information visit: https://github.com/jaydenseric/graphql-multipart-request-spec

from simple_graphql_client import GraphQLClient

headers = {'Authorization': 'Bearer ...'}

client = GraphQLClient("https://...", headers=headers)

query = "..."
filename = "..."
variables = {
    ...
    'file': None,
    ...
}

with open(filename, "rb") as file:
    files = [
        ('file', (filename, file))
    ]

    response = client.query_with_files(query=query, variables=variables, files=files)

Executing a query with a multiple files

from simple_graphql_client import GraphQLClient

client = GraphQLClient("https://...")

query = "..."
filenames = ["...", "..."]
files = []
variables = {
    ...
    'files': [None, None]
    ... 
}

for i, filename in enumerate(filenames):
    variable = 'files.{}'.format(i)
    files.append((variable, (filename, open(filename, "rb"))))

response = client.query_with_files(query=query, variables=variables, files=files)

Setting a query-specific header

This argument will override the default header which can be set in the GraphQLClient

response = client.query(query=query, variables=variables, files=files, headers=headers)
response = client.query_with_files(query=query, variables=variables, files=files, headers=headers)

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts