Tevin Joseph K O
Tevin Joseph K O

Reputation: 2654

How to hit external graphql URL using gql

How to hit external graphql URL using gql?

As per github repo:

from gql import gql, Client

client = Client(schema=schema)
query = gql('''
{
  hello
}
'''
)

client.execute(query)

Even though, the author say it is inspired by apollo client ,I didn't see any way of providing URL while executing the graphql.

Upvotes: 2

Views: 862

Answers (1)

L3viathan
L3viathan

Reputation: 27283

The client accepts an optional transport parameter, on which you can give an instance of gql.transport.requests.RequestsHTTPTransport.

Its first parameter is the URL:

from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport
transport = RequestsHTTPTransport("http://example.com")
client = Client(schema=schema, transport=transport)
query = gql('''
{
  hello
}
'''
)

Upvotes: 3

Related Questions