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

Is it possible to get Juniper and graphql-client working together? #550

Closed
DaleLJefferson opened this issue Mar 3, 2020 · 1 comment
Closed
Labels

Comments

@DaleLJefferson
Copy link

I'm building a website that exposes a graphQL api but I would also like to use the graphQL api server-side. I assumed graphql-client would work with juniper since they are related projects but I can't seem to work out how to wire them up.

// I was hoping to do something like this

#[derive(GraphQLQuery)]
#[graphql(schema_path = "schema.graphql", query_path = "hello_query.graphql")]
struct HelloQuery;

let (res, _errors) = juniper::execute(
    "query { hello }",
     None,
     &schema,
     &juniper::Variables::new(),
     &ctx,
).unwrap();

let hello: hello_query::ResponseData = res
// This is the best I have so far converting to json and back again

#[derive(GraphQLQuery)]
#[graphql(schema_path = "schema.graphql", query_path = "hello_query.graphql")]
struct HelloQuery;

let (res, _errors) = juniper::execute(
    "query { hello }",
     None,
     &schema,
     &juniper::Variables::new(),
     &ctx,
).unwrap();

let hello: hello_query::ResponseData =
        serde_json::from_str(&serde_json::to_string(&res).unwrap()).unwrap();

Also, the Juniper Value does not work with serde_json::from_value(res)

@DaleLJefferson DaleLJefferson changed the title Is it possible to get Juniper and graphql-client working together Is it possible to get Juniper and graphql-client working together? Mar 3, 2020
@LegNeato
Copy link
Member

LegNeato commented Mar 9, 2020

When #324 it lands should be easier in 2 passes. I'm not sure we can do it at compile time...juniper needs to build and know the schema before the client can be generated.

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

No branches or pull requests

2 participants