-
Notifications
You must be signed in to change notification settings - Fork 110
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
Allow fetching a schema via introspection (instead of an SDL file) #4
Comments
I have the use case. |
@AlwxSin thanks! What kind of auth would you need, if any? |
@benjaminjkraft |
@benjaminjkraft, same goes here via https://github.com/movio/bramble, |
Ah, interesting. Would you want the custom headers to be in the configuration file, or dynamic (e.g. you'd want to set them via arguments/envvars, differently for different invocations)? I'm a bit worried that there's no way to support every kind of auth folks will want, although we could also make you call |
For us a configuration file would be awesome! Ideally in there we would be able to specify an arbitrary set of different HTTP headers. -- Hey if you're looking for a hand, I see this issue is labelled as "help wanted", I'd be more than keen to help out 👍 love this project idea! |
Hey @benjaminjkraft, just want to provide a correction to my comment earlier - gateway introspection queries in bramble do not react to this tenant header I speak of (thanks to @lucianjon for clarifying this). Indeed it is only the |
@suessflorian that would be great! |
Hey @benjaminjkraft, just an FYI if you're interested. After more and more research I think long term the ability to generate a schema from introspection has reason to live in https://github.com/graphql-go/graphql, mirror of https://github.com/graphql/graphql-js, as I see pieces of the puzzle living in this JS reference implementation. ie, But this may take a while and I'm really keen to start using
So far, I've had a little bit of time to get a rough (like really really rough) sketch together here: https://github.com/suessflorian/graphql-server-introspection-sdl-go, only prints schema directives at this stage, will get onto finalising tomorrow and black box testing (re: JS implementation input/output) before opening a PR here with this component available 👍 |
Neat! Yeah, importing it makes sense, that's a good point. Another option as the temporary (or permanent) solution is to just have it as a separate tool that users can call out to before genqlient: //go:generate go run command/to/build/schema ...
//go:generate go run github.com/Khan/genqlient I actually wonder if that's the best way to do it; that way that tool can have its own options, configuration, etc. We could document it as a recommended approach even if separate. But I can also see the convenience of having it wired into genqlient. Do note we use https://github.com/vektah/gqlparser, not graphql-go. In principle there's no need to match (certainly not if it's a standalone tool) but it's probably cleaner if we do (then we could maybe skip serializing the SDL and then deserializing it, and just generally decrease new deps). From a quick look, the tool looks quite reasonable :-) . |
Hey @benjaminjkraft, so I've got a full build client schema functionality tool ready to go: https://github.com/suessflorian/gqlfetch, I've taken your advice and made it standalone first. I've also aligned with https://github.com/vektah/gqlparser hosted gql schema AST. Although I have found how to go directly from introspection to the internal AST, I will need to make some decent extensions to the AST type with some fairly hefty unmarshalling methods. Benchmarks of this standalone tool at this stage if you're curious; sub 250ms for a 440 type schema (~3800line sdl), interestingly ~98% time spent unmarshalling rest string building. Where do you think we go from here you reckon (I'm completely impartial)?
|
That seems super neat, thanks! If it's too complicated to build the AST directly, it's also fine to go via source. As for where to host this, I'd lean towards something standalone, as long as the ergonomics aren't too bad, which it seems they wouldn't be. (At least until some potential future where gqlgen has plugins.) But I'm very happy to have it documented with genqlient -- you could add a little example to the FAQ and/or mention it inline with But let me also pull in @StevenACoffman who is involved with the gqlgen/gqlparser working group, since there's talk of pulling genqlient into the potential forthcoming gqlgen org. If that all happens, it may make sense to pull your project into that org as well. Steve, let me know if you have thoughts on what level of integration makes sense! |
Sounds good @benjaminjkraft, I'm game for anything and keen to help out. My PR highlights a FAQ portion explaining how it can currently be used, but ofc always keen to amend as needed. |
…145) During generation we parse the schema using [`gqlparser.LoadSchema`](https://github.com/vektah/gqlparser/blob/2a3d320c0f1d31f404cc36f6cce8f7f93b016682/gqlparser.go#L11) over [here](https://github.com/Khan/genqlient/blob/a4aa6d9bb0f45cb71b3b7816742172011d96fbc1/generate/parse.go#L34). As you can see `gqlparser.LoadSchema` uses it's sub directory declared [`validator.LoadSchema`](https://github.com/vektah/gqlparser/blob/2a3d320c0f1d31f404cc36f6cce8f7f93b016682/gqlparser.go#L12) - but prepends a schema with [typical implicit declared types](https://github.com/vektah/gqlparser/blob/2a3d320c0f1d31f404cc36f6cce8f7f93b016682/validator/prelude.go#L5). Full server schema introspection exposes the entire schema explicitly, hence causing a clash with this prelude schema rendering introspection derived schemas to fail. Here I just introduce a two stage schema parsing step to accomodate both implicit and explicit sdl's. -- I have also added to the FAQ as per #4 how we can use introspection to fetch the schema when using `genqlient`. Co-authored-by: Ben Kraft <ben@benkraft.org>
Hey, btw, I brought this up with the other working group members, and we're going to decide at the next monthly meeting. We need to freshen up https://github.com/99designs/gqlgen-contrib as well. |
We'll probably just want to convert it to SDL. There are tools in Node to do that -- see e.g. this gist or this package which users can invoke themselves as a workaround. I don't see any in Go, so we might have to port the relevant parts of graphql-js (see the gist).
The text was updated successfully, but these errors were encountered: