Giter VIP home page Giter VIP logo

Comments (11)

jxnu-liguobin avatar jxnu-liguobin commented on June 25, 2024

introspection?

from cynic.

obmarg avatar obmarg commented on June 25, 2024

@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.

from cynic.

jxnu-liguobin avatar jxnu-liguobin commented on June 25, 2024

@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.

from cynic.

jxnu-liguobin avatar jxnu-liguobin commented on June 25, 2024

@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.

from cynic.

obmarg avatar obmarg commented on June 25, 2024

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.

from cynic.

jxnu-liguobin avatar jxnu-liguobin commented on June 25, 2024

@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))

from cynic.

obmarg avatar obmarg commented on June 25, 2024

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.

from cynic.

jxnu-liguobin avatar jxnu-liguobin commented on June 25, 2024

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).

from cynic.

obmarg avatar obmarg commented on June 25, 2024

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.

from cynic.

jxnu-liguobin avatar jxnu-liguobin commented on June 25, 2024

👌

from cynic.

obmarg avatar obmarg commented on June 25, 2024

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.

from cynic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.