def test_retries(execute_mock): expected_retries = 3 execute_mock.side_effect = Exception("fail") client = Client(retries=expected_retries, transport=RequestsHTTPTransport( url='https://fierce-crag-44069.herokuapp.com/graphql')) query = gql(''' { myFavoriteFilm: film(id:"RmlsbToz") { id title episodeId } } ''') with pytest.raises(Exception): client.execute(query) assert execute_mock.call_count == expected_retries
def client(): request = requests.get('https://fierce-crag-44069.herokuapp.com/graphql', headers={ 'Host': 'fierce-crag-44069.herokuapp.com', 'Accept': 'text/html', }) request.raise_for_status() csrf = request.cookies['csrftoken'] return Client(transport=RequestsHTTPTransport( url='https://fierce-crag-44069.herokuapp.com/graphql', cookies={"csrftoken": csrf}, headers={'x-csrftoken': csrf}), fetch_schema_from_transport=True)
def client(api_key, secret_key, use_batching=False, timeout=None, **kwargs): url = 'https://api2.orionx.io/graphql' if use_batching: cs = CustomBatchTransport(api_key, secret_key, url=url, use_json=True, timeout=timeout) else: cs = CustomSessionTransport(api_key, secret_key, url=url, use_json=True, timeout=timeout) client = Client(transport=cs, fetch_schema_from_transport=True, **kwargs) return client
def typedef_schema(): return Client(type_def=''' schema { query: Query } interface Character { appearsIn: [Episode] friends: [Character] id: String! name: String } type Droid implements Character { appearsIn: [Episode] friends: [Character] id: String! name: String primaryFunction: String } enum Episode { EMPIRE JEDI NEWHOPE } type Human implements Character { appearsIn: [Episode] friends: [Character] homePlanet: String id: String! name: String } type Query { droid(id: String!): Droid hero(episode: Episode): Character human(id: String!): Human }''')
def introspection_schema(): return Client(introspection=introspection)
def local_schema(): return Client(schema=StarWarsSchema)
def client(): return Client(schema=StarWarsSchema)
def ds(): client = Client(schema=StarWarsSchema) ds = DSLSchema(client) return ds