2016-09-23 123 views
2

如何将多个查询分批发送到GitHub的GraphQL API的单个请求中?如何批量GitHub GraphQL API查询?

例如,如何将这两个查询分批到一个请求中并接收单个响应?而且这种技术可以处理更多的查询(比如200)吗?

{ 
    repositoryOwner(login:"rails") { 
    repository(name:"rails") { 
     description 
     homepageURL 
    } 
    } 
} 

{ 
    repositoryOwner(login:"github") { 
    repository(name:"graphql-client") { 
     description 
     homepageURL 
    } 
    } 
} 

(GitHub的GraphQL API可以与https://developer.github.com/early-access/graphql/explorer/试行)

回答

5

您需要调用换到这两个领域在一个查询:

{ 
    repositoryOwner(login:"rails") { 
    repository(name:"rails") { 
     description 
     homepageURL 
    } 
    } 
    repositoryOwner(login:"github") { 
    repository(name:"graphql-client") { 
     description 
     homepageURL 
    } 
    } 
} 

这仍然会失败但是,作为现在在输出中有两个字段具有相同名称(repositoryOwner),因此您需要将它们别名:

{ 
    rails: repositoryOwner(login:"rails") { 
    repository(name:"rails") { 
     description 
     homepageURL 
    } 
    } 
    graphql_client: repositoryOwner(login:"github") { 
    repository(name:"graphql-client") { 
     description 
     homepageURL 
    } 
    } 
} 

请参阅this explanation

如果你可以为每个查询生成一个唯一的别名,那么是这个技术应该可以正常工作。