5 unstable releases

0.3.0 Jun 6, 2021
0.2.1 Apr 8, 2021
0.2.0 Apr 7, 2021
0.1.1 Apr 7, 2021
0.1.0 Apr 5, 2021

#1406 in Rust patterns


Used in gurkle-cli

Apache-2.0 OR MIT

485KB
13K SLoC

Rust 7K SLoC // 0.0% comments GraphQL 6.5K SLoC // 0.0% comments

Gurkle

Github actions Status docs crates.io

GraphQL client for Rust, with typed requests and responses, and subscriptions!

Features

  • Precise types for query variables and responses.
  • Supports GraphQL fragments, objects, unions, inputs, enums, custom scalars and input objects.
  • Subscriptions support.
  • Copies documentation from the GraphQL schema to the generated Rust code.
  • Arbitrary derives on the generated responses.
  • Arbitrary custom scalars.
  • Supports multiple operations per query document.
  • Supports setting GraphQL fields as deprecated and having the Rust compiler check their use.

Usage

  • Install the CLI tool (cargo install gurkle-cli)
  • Run gurkle generate --schema-path <your schema> path/to/operations/*.graphql
  • This will generate a generated.rs in your current directory.
  • include!("./generated.rs") into the .rs file of your choice
    • You may need to import types used by the custom scalars into this file, or use type definitions.

Custom scalars

The generated code will reference the scalar types as defined in the server schema. This means you have to provide matching rust types in the scope of the struct under derive. It can be as simple as declarations like type Email = String;. This gives you complete freedom on how to treat custom scalars, as long as they can be deserialized.

Deprecations

The generated code has support for @deprecated field annotations.

Documentation for the generated modules

You can use cargo doc --document-private-items to generate rustdoc documentation on the generated code.

Code of Conduct

Anyone who interacts with this project in any space, including but not limited to this GitHub repository, must follow our Code of Conduct.

License

Licensed under either of these:

Contributing

Unless you explicitly state otherwise, any contribution you intentionally submit for inclusion in the work, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions.


lib.rs:

Crate for internal use by other graphql-client crates, for code generation.

It is not meant to be used directly by users of the library.

Dependencies

~2.2–3MB
~63K SLoC