Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize the client? #1

Closed
F21 opened this issue Jun 1, 2017 · 6 comments
Closed

Generalize the client? #1

F21 opened this issue Jun 1, 2017 · 6 comments
Labels

Comments

@F21
Copy link

F21 commented Jun 1, 2017

Going by the examples, it looks like this might be great as a general graphql client that should be able to query any graphql server. Maybe a command line tool can be provided to run an introspection query against a graphql server to generate the appropriate types as well.

@dmitshur
Copy link
Member

dmitshur commented Jun 1, 2017

Yes, in the long term, absolutely.

As I wrote in google/go-github#646:

  • It's very likely the end result package can be entirely generated. The GraphQL schema is entirely introspectable and very structured, and strongly typed. See https://developer.github.com/v4/guides/intro-to-graphql/#discovering-the-graphql-api. Aside from prototyping an initial version, there's really no need to write/maintain the entire package manually.

  • Nothing about this is GitHub specific. It's GraphQL specific. A good solution to this will likely apply to any other GraphQL API.

Once development is closer to completed, and this package is more stable and mature, I think I'll see about factoring out the common GraphQL-specific aspects and the generator into a separate component.

githubql itself will be 100% specific to GitHub's GraphQL schema, but you will be able to easily create/generate similar Go client libraries for other GraphQL schemas.

It's likely the only parameters the client generator will need is the URL of a GraphQL endpoint (for introspection) and the name.

@F21
Copy link
Author

F21 commented Jun 1, 2017

Another request I have (once the package is generalized), is to make the transport pluggable. For example, I am currently using graphql over grpc. So, it would be nice if the package comes with a default HTTP transport, but provides an interface so that we can implement other types of transports.

@dmitshur
Copy link
Member

dmitshur commented Jun 1, 2017

NewClient already takes an *http.Client parameter. If you leave it as nil, then http.DefaultClient is used, otherwise the custom HTTP client. A custom transport can be provided as part of a custom *http.Client, see http.Client.Transport.

Is that what you're asking for, or are you referring to something else?

@F21
Copy link
Author

F21 commented Jun 1, 2017

In terms of GRPC, we do not use the http.Client directly although GRPC is built on top of HTTP/2. It is wrapped by the GRPC client which provides more features on top of http.Client. Therefore, I can't pass a http.Client to NewClient if I want to use GRPC as my transport.

Here's a pretty good example of a generated GRPC client being used: https://github.com/grpc/grpc-go/blob/master/examples/helloworld/greeter_client/main.go

@dmitshur
Copy link
Member

dmitshur commented Jun 1, 2017

I see. That NewGreeterClient func takes a *grpc.ClientConn.

I'm not quite sure how to deal with this, but I want to support it if possible. Mind opening a new specific issue where we can track it and discuss it in more detail?

@dmitshur
Copy link
Member

This issue has been resolved by shurcooL/graphql@6ac8ee2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants