예제 #1
0
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
예제 #2
0
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)
예제 #3
0
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
예제 #4
0
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
}''')
예제 #5
0
def introspection_schema():
    return Client(introspection=introspection)
예제 #6
0
def local_schema():
    return Client(schema=StarWarsSchema)
예제 #7
0
def client():
    return Client(schema=StarWarsSchema)
예제 #8
0
def ds():
    client = Client(schema=StarWarsSchema)
    ds = DSLSchema(client)
    return ds