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

Support build time introspection queries #62

Closed
obmarg opened this issue Jul 5, 2020 · 11 comments
Closed

Support build time introspection queries #62

obmarg opened this issue Jul 5, 2020 · 11 comments
Labels
✨ enhancement New feature or request
Milestone

Comments

@obmarg
Copy link
Owner

obmarg commented Jul 5, 2020

For some use cases, it might make sense to query for a schema at build time from a running server. Should think about supporting those use cases.

@obmarg obmarg added the ✨ enhancement New feature or request label Jul 5, 2020
@jxnu-liguobin
Copy link
Contributor

introspection?

@obmarg
Copy link
Owner Author

obmarg commented Mar 4, 2021

@jxnu-liguobin graphql servers support "introspection queries": https://graphql.org/learn/introspection/ which let you ask a server about it's schema. You can build up a schema from these, which cynic could use instead of a schema on the filesystem like it uses currently.

Although cynic would first need to support introspection queries, as it doesn't currently.

@jxnu-liguobin
Copy link
Contributor

@obmarg Yes, I'll think about it and see if I can make it.
I think we can continue to use schema_ path property to set the introspection server address.

@jxnu-liguobin
Copy link
Contributor

@obmarg Hi,
So, what I want to do is to implement a similar function load_schema_from_server?

image

Here, suppose we use the HTTP URL setting schema_path, every derive macro needs to read schema_path when using introspection, it may need to add a layer of cache here to avoid the acquisition failure and efficiency problems.

@obmarg
Copy link
Owner Author

obmarg commented Mar 5, 2021

Yeah, that is roughly what you'd want.

Indeed a cache would be good - would definitely like to avoid running an introspection query for every single derive.

@jxnu-liguobin
Copy link
Contributor

@obmarg
Since introspection itself is also a graphql, we need graphql query, and we may need a config similar to schema_path.
How to configure this? Or the schema_path change path to a struct(I'm not sure I can do that).
(the introspection results can refer to the introspection decoding implementation of graphql-client, or directly introduce it .(it's really not good))

@obmarg
Copy link
Owner Author

obmarg commented Mar 21, 2021

Sorry for the delay getting back to you @jxnu-liguobin - I've not had any time to pay attention to cynic the past couple of weeks.

You're correct that we will need an introspection query implementation to do this. I've got a WIP cynic implementation of one sitting on my machine (I was looking into doing this a couple of months ago, but got distracted by other bits). I've uploaded it to this branch if you want to have a look. I can't remember what needed fixed in it - it may be easy or may be some missing feature in cynic that we need in order to finish it off.

As for how to configure this: I am not entirely sure. Given that we probably don't want to make a request for every derive and GraphQL servers can sometimes require authentication or other configuration I'm not sure it even makes sense to update the derives to make an introspection query. The number of options we'd need to support is quite large, and caching might be difficult.

Maybe it makes more sense to provide users the ability to run an introspection query and output a schema.graphql file from that. Then users can write a build.rs or similar to fetch their query using the functionality we provide, and the derives can just read the schema.graphql that outputs. Seems like it might be a lot easier to implement things that way.

@jxnu-liguobin
Copy link
Contributor

Maybe it makes more sense to provide users the ability to run an introspection query and output a schema.graphql file from that. Then users can write a build.rs or similar to fetch their query using the functionality we provide, and the derives can just read the schema.graphql that outputs. Seems like it might be a lot easier to implement things that way.

Yes, it will be easier.

You're correct that we will need an introspection query implementation to do this. I've got a WIP cynic implementation of one sitting on my machine (I was looking into doing this a couple of months ago, but got distracted by other bits). I've uploaded it to this branch if you want to have a look. I can't remember what needed fixed in it - it may be easy or may be some missing feature in cynic that we need in order to finish it off.

It looks like only the structure is defined, which looks fine if the user writes the low-level API himself(users need write build.rs to executes graphql query).

@obmarg
Copy link
Owner Author

obmarg commented Mar 22, 2021

It looks like only the structure is defined, which looks fine if the user writes the low-level API himself(users need write build.rs to executes graphql query).

Yeah, I only got as far as writing the structure of an introspection query. We'll also need to write the code that converts the results of an introspection query into a schema.

I'd probably let users write the actual HTTP call & output of the schema themselves. It's not too hard to do, and there's a fairly wide variety of ways to do it: different HTTP clients, different authentication schemes etc. so be quite hard to cover all the possibilities. Can provide some examples in the repository that users can use as a starting point.

@jxnu-liguobin
Copy link
Contributor

👌

@obmarg obmarg modified the milestones: 3.0.0, 3.1.0 May 7, 2023
@obmarg
Copy link
Owner Author

obmarg commented Aug 5, 2023

Between cynic-introspection & cynic-cli this is now supported. It's not fully documented, but I wouldn't recommend this approach for most users anyway.

A smart user who wants to go against my recommendation should hopefully be able to figure it out for themselves.

@obmarg obmarg closed this as completed Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants