Skip to content

minghuadev/python-graphql-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-graphql-client

Simple GraphQL client for Python 2.7+

Install

pip install graphqlclient

Usage

from graphqlclient import GraphQLClient

client = GraphQLClient('http://graphql-swapi.parseapp.com/')

result = client.execute('''
{
  allFilms {
    films {
      title
    }
  }
}
''')

print(result)

Authorization

Authorization tokens can be added to the request using the client's addToken method:

client.addToken('very-long-and-secure-token')

which defaults to http header name Authorization. An alternative http header name for the token can be set by passing in the alternative header name, e.g. for x-api-key:

client.addHeader('very-long-and-secure-token','x-api-key')


Note: there are different ways of specifying token so token maybe like these:
	# this is the standard form
  addHeader('Bearer {}'.format(tokenStr)) or
    # alternatives that I haven't used
  addHeader('token {}'.format(tokenStr))  there are others..

If you need more options for headers use

client.addHeader({'your_custom_header_name' : 'your_custom_header_value' ,
                       'your_custom_header_name_2' :'your_custom_header_value_2'})

License

MIT License

About

Simple GraphQL client for Python 2.7+

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%