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

unresolved import serde use of undeclared crate or module serde #427

Open
daweth opened this issue Jun 27, 2022 · 4 comments · May be fixed by #487
Open

unresolved import serde use of undeclared crate or module serde #427

daweth opened this issue Jun 27, 2022 · 4 comments · May be fixed by #487

Comments

@daweth
Copy link

daweth commented Jun 27, 2022

When following example code, I get the following error:

unresolved import `serde`
use of undeclared crate or module `serde`
@tomhoule
Copy link
Member

Is serde in your Cargo.toml?

@riverfr0zen
Copy link

It should mention in the README what crates and features are necessary to run the examples. Another e.g.: It's not straightforward to people new to the ecosystem that "json" is a feature that must be enabled for reqwest. You have to dig into the Github example to see that.

reqwest = { version = "^0.11", features = ["json", "blocking"] }

@spencerwilson
Copy link

spencerwilson commented May 26, 2023

Is it a bug that to use graphql_client I also have to have serde explicitly included in my crate's dependencies? I see serde named in graphql_client's own dependencies, so it's somewhat surprising I have to include it, too. (caveat: I'm very new to Rust and would be grateful for any teachings people are in the mood to give)

@UrzaMancer
Copy link

I've run into the same issue: glad the discussion is here and I'll add serde to my Cargo.toml, but it's also not clear to me why this is so. (I am also new to working with packages that make use of macros in this fashion)

swlynch99 added a commit to swlynch99/graphql-client that referenced this issue May 30, 2024
This PR makes the serde derives emitted by `#[derive(GraphQLQuery)]` use
a private re-export of the serde crate instead of relying on users of
this crate having added serde to their `Cargo.toml`.

Serde allows you to add an annotation

    #[serde(crate = "<path to crate>")]

for exactly this reason so most of this PR is just plumbing the correct
path through the codegen crate to the correct annotation.

Details
-------
- There is a new `#[doc(hidden)] mod _private` declaration in the
  `graphql_client` crate. All re-exports (which is just serde) have been
   placed there.
- I have added a new `serde_path` field to `GraphQLCodegenOptions` which
  defaults to `::serde`. This means that the code generated by the CLI
  should remain effectively unchanged.
- The rest is just applying `#[serde(crate = ...)]` annotations where
  appropriate.

Fixes graphql-rust#427
swlynch99 added a commit to swlynch99/graphql-client that referenced this issue May 30, 2024
This PR makes the serde derives emitted by `#[derive(GraphQLQuery)]` use
a private re-export of the serde crate instead of relying on users of
this crate having added serde to their `Cargo.toml`.

Serde allows you to add an annotation

    #[serde(crate = "<path to crate>")]

for exactly this reason so most of this PR is just plumbing the correct
path through the codegen crate to the correct annotation.

Details
-------
- There is a new `#[doc(hidden)] mod _private` declaration in the
  `graphql_client` crate. All re-exports (which is just serde) have been
   placed there.
- I have added a new `serde_path` field to `GraphQLCodegenOptions` which
  defaults to `::serde`. This means that the code generated by the CLI
  should remain effectively unchanged.
- The rest is just applying `#[serde(crate = ...)]` annotations where
  appropriate.

Fixes graphql-rust#427
swlynch99 added a commit to swlynch99/graphql-client that referenced this issue May 30, 2024
This PR makes the serde derives emitted by `#[derive(GraphQLQuery)]` use
a private re-export of the serde crate instead of relying on users of
this crate having added serde to their `Cargo.toml`.

Serde allows you to add an annotation

    #[serde(crate = "<path to crate>")]

for exactly this reason so most of this PR is just plumbing the correct
path through the codegen crate to the correct annotation.

Details
-------
- There is a new `#[doc(hidden)] mod _private` declaration in the
  `graphql_client` crate. All re-exports (which is just serde) have been
   placed there.
- I have added a new `serde_path` field to `GraphQLCodegenOptions` which
  defaults to `::serde`. This means that the code generated by the CLI
  should remain effectively unchanged.
- The rest is just applying `#[serde(crate = ...)]` annotations where
  appropriate.

Fixes graphql-rust#427
swlynch99 added a commit to swlynch99/graphql-client that referenced this issue May 30, 2024
This PR makes the serde derives emitted by `#[derive(GraphQLQuery)]` use
a private re-export of the serde crate instead of relying on users of
this crate having added serde to their `Cargo.toml`.

Serde allows you to add an annotation

    #[serde(crate = "<path to crate>")]

for exactly this reason so most of this PR is just plumbing the correct
path through the codegen crate to the correct annotation.

Details
-------
- There is a new `#[doc(hidden)] mod _private` declaration in the
  `graphql_client` crate. All re-exports (which is just serde) have been
   placed there.
- I have added a new `serde_path` field to `GraphQLCodegenOptions` which
  defaults to `::serde`. This means that the code generated by the CLI
  should remain effectively unchanged.
- The rest is just applying `#[serde(crate = ...)]` annotations where
  appropriate.

Fixes graphql-rust#427
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants