【问题标题】:How to hit external graphql URL using gql如何使用 gql 访问外部 graphql URL
【发布时间】:2018-04-15 00:10:49
【问题描述】:

如何使用gql 访问外部graphql URL?

根据 github 仓库:

from gql import gql, Client

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

client.execute(查询)

尽管作者说它是受到apollo client 的启发,但我在执行graphql 时没有看到任何提供URL 的方法。

【问题讨论】:

    标签: python graphql graphene-python


    【解决方案1】:

    客户端accepts 一个可选的transport 参数,您可以在其上提供gql.transport.requests.RequestsHTTPTransport 的实例。

    它的第一个参数是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
    }
    '''
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 2016-08-01
      • 2013-05-20
      • 1970-01-01
      • 1970-01-01
      • 2019-06-29
      • 2013-07-02
      相关资源
      最近更新 更多