graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

[Documentation] README gives self-contradicting advice

Open ehiggs opened this issue 3 years ago • 1 comments

The README says the following:

In order to provide precise types for a response, graphql_client needs to read the query and the schema at compile-time.

To download the schema, you have multiple options. This projects provides a CLI, however it does not matter what tool you use, the resulting schema.json is the same.

We now have everything we need to derive Rust types for our query. This is achieved through a procedural macro, as in the following snippet:

use graphql_client::GraphQLQuery;

// The paths are relative to the directory where your `Cargo.toml` is located.
// Both json and the GraphQL schema language are supported as sources for the schema
#[derive(GraphQLQuery)]
#[graphql(
    schema_path = "tests/unions/union_schema.graphql",
    query_path = "tests/unions/union_query.graphql",
)]
pub struct UnionQuery;

The first command will create a json. "We now have everything we need to derive Rust types for our query". But then the code points to some graphql schema that we do not have. Trying various things with the graphql-client tool I can't see how to distill a graphql schema. Instead I've been using gql-cli from python to work around this.

If this is all possible in graphql-client, it should be documented here. Else, it would be a good feature so the docs work as written. :)

ehiggs avatar Apr 07 '22 21:04 ehiggs

I'll leave this here as I also struggled with this... Schema files are interchangeable, using a .json in place of a .graphql is perfectly fine and vice versa.

Both

#[derive(GraphQLQuery)]
#[graphql(
    schema_path = "tests/unions/union_schema.graphql",
    query_path = "tests/unions/union_query.graphql",
)]
pub struct UnionQuery;

and

#[derive(GraphQLQuery)]
#[graphql(
    schema_path = "tests/unions/union_schema.json",
    query_path = "tests/unions/union_query.graphql",
)]
pub struct UnionQuery;

should work.

neoreddog avatar Dec 25 '22 17:12 neoreddog