All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
- Revert integer ID deserialization support (introduced in #476). It introduced regressions.
- Support for
deprecateddirective on InputValue fields (#553) - Support for custom variable and response types (#536)
- Allow using
#[derive(GraphQLQuery)]without depending onserdedirectly (#487) - CLI option for extern enums (#520)
- Support deserializing IDs from integers or strings (#476)
- Introspection schema now includes
oneOfandspecifiedByUrl(#501) - Update
reqwestto 0.12 (#499) - Fix required ID deserialization (#523)
- Fix
skip_serializing_nonefor root level variables (#485) - Use consistent reference to
graphql_clientcrate in codegen (#484) - Fix multiple operations example in README (#497)
- Add support for GraphQL’s
extend typedirective - Add support for
graphqls://schema - Expose
generate_module_token_stream_from_stringto allow custom macro wrappers
- Add support for
@oneOf - Update Ubuntu image for CI
- Switch to BTree to make codegen's output deterministic
- Add support for
skip_noneandskip_serializing_none - Fix CI
- The
variables_derivesnow trims whitespace from individual derivation traits. - The new
reqwest-rustlsfeature works like thereqwestfeature but withrustlsrather thannative-tls. - Code generated by the
graphql-clientCLI program now suppresses all warnings from rustc and clippy. - Derive from both variables and response for enum
- Camel case input variables in .graphql files now generate snake_case variable names in Rust
- Support Paths in response derives
- cli: Display server responses when introspection failed
- upgrade to graphql_parser 0.4
- Add support for
fragments-other-variant
- The
webfeature is dropped. You can now use areqwest::Clientinstead of the custom HTTP client. - Allow specifying externally defined enums (thanks @jakmeier)
- Make the derive feature optional (but enabled by default)
--no-sslparam in CLI (thanks @danielharbor!)- The shape of some generated response types changed to be flatter and more ergonomic.
- Many dependencies were dropped
- A CLI and derive option to specify a module to import custom scalar from. Thanks @miterst! (PR)
- The introspection query response shape internally
used by graphql-client is now its own crate,
graphql-introspection-query. - A new experimental
normalizationattribute, that renames all generated names to camel case. By default, the"none"naming conventions are used, however, if set to"rust", Rust naming rules will be used instead. This may become the default in future versions, since not normalizing names can lead to invalid code. (thanks @markcatley!) response_derivesnow only applies to responses. Usevariables_derivesfor variable structure derives.
- (BREAKING) In the CLI, there was a conflict between the short forms
--output-directoryand--selected-operationsince they were both-o. After this fix,-ois the short form of--output-directory. (thanks @davidgraeff!) - Catch more cases where a rust keyword in schemas or queries would break code generation (thanks @davidgraeff!)
- (BREAKING) This release sees the switch to the Rust 2018 edition - it is only compatible with Rust 1.31.0 and later. In particular, this changes how the derive macro is imported. See the README for more details.
graphql_client_webis now deprecated. The browser client has been moved to thegraphql_clientcrate, under thewebmodule. It is only available with thewebfeature enabled on thewasm32-unknown-unknowntarget.
- In the CLI, both --selected-operation and --output used the -o shorthand. --output now uses -out.
-
The
selected_operationderive attribute is deprecated. The name of the struct under derive now has to match one of the operations defined in the query file. -
The CLI now takes the schema path as a required keyword argument.
-
The CLI was revamped to generate separate modules for each operation in a given query file.
The idea now is that if you generate code for the following document:
# In my_query.graphql query QueryA { .... } query QueryB { .... } mutation SomeMutation { ... }
The CLI generated code will look like this:
// In my_query.rs pub struct QueryA; pub mod query_a { ... } pub struct QueryB; pub mod query_b { ... } pub struct SomeMutation; pub mod some_mutation { ... }
That way the operations don't live in the same module, there is no risk of names clashing anymore.
- Changes to query files will now always trigger code generation for the corresponding modules on the next build.
- If there is no
schemadeclaration in a schema, the root types will be matched by name (Query,MutationandSubscription).
- Enums now always derive PartialEq and Eq by default
- Code generation for fragments on unions was fixed
- Support for recursive fragments and input types
- The graphql-parser dependency version is no longer pinned
-
The CLI can now optionally format the generated code with rustfmt (enable the
rustfmtfeature). -
When deriving, the generated module now has the same visibility (private,
pub,pub(crate)orcrate) as the struct under derive. -
Codegen now supports type-refining fragments, i.e. fragments on interfaces or unions that only apply to one of the variants. Example:
type Pie { diameter: Integer name: String } type Sandwich { length: Float ingredients: [String] } union Food = Sandwich | Pie type Query { lunch: Food } fragment PieName on Pie { name } query Test { lunch { ...PieName ...on Sandwich { length } } }
- (BREAKING) GraphQLQuery does not take a lifetime parameter anymore. This makes it easier to work with futures in async client, since futures expect everything they capture to have the 'static lifetime.
- (BREAKING) Removed the
Rustprefix on the name of generated items. - (BREAKING) If you don't set
--selected-operationoptions withgraphql-client generate, the cli generate all queries in query file.
- When using edition 2018, you no longer need to add
#[macro_use] extern crate serde_deriveto your crate for the generated modules to compile (thanks @aergonaut!)
- Better error messages from the derive macro stwhen the schema or the query file path is not found.
- Support both full introspection responses (with "data") field and just the content of the "data" field in schema.json files.
-
Support for
@deprecatedfield annotations. You can configure how deprecations are handled via thedeprecatedargument in theGraphQLQueryderive:#[derive(GraphQLQuery)] #[graphql( schema_path = "src/graphql/schema.json", query_path = "src/graphql/queries/my_query.graphql", deprecated = "warn" )] pub struct MyQuery;
Valid values are:
allow: the response struct fields are not marked as deprecated.warn: the response struct fields are marked as#[deprecated].deny: The struct fields are not included in the response struct and using them is a compile error.
The default is
warn.This is a breaking change if you have the
#[deny(deprecated)]compiler lint and you use deprecated fields in your queries. The quick solution is to annotate the relevant queries withdepracated = "allow"as shown above. -
The CLI now supports the
--authorizationflag to pass the contents of anAuthorizationheader. Thanks to @h-michael for the PR! -
Improved some codegen error messages, giving more context. Thanks @mathstuf!
-
Aliases in queries are now supported. Beyond the ergonomics, this is an important feature since it allows to query the same field on an object multiple times with different arguments, as shown in the official guide. Thanks a lot @mathstuf!
-
The traits in
response_derivesare now used for input types (variables) as well. In the future we may want to separate the options, but we will first experiment this way. -
Most of the
graphql-query-derivecrate was factored out into a newgraphql-client-codegencrate that should enable code generation through means other than custom derives (CLI, build scripts...). Thanks @h-michael for this important refactoring! -
Top-level exported types have been renamed. Types no longer have a
GraphQLprefix. e.g.GraphQLQuery->Query,GraphQLError->Error. -
For several classes of items that we generate, we only generate those that are actually used by the query. This way, you do not need to define mappings for every scalar in the schema you are querying - even for small queries - anymore. This also improves compile times a lot in some scenarios. (#116 - thanks @mathstuf!)
-
GraphQLErrornow implements theDisplaytrait. -
Basic support for fragments on interfaces. See #154 for what is not supported yet.
-
Handle all Rust keywords as field names in codegen by appending
_to the generated names, so a field calledtypein a GraphQL query will become atype_field in the generated struct. Thanks to @scrogson! -
The
operationNamefield is now correctly set on request bodies.
There are a number of breaking changes due to the new features, read the Added section attentively if you are upgrading.
- (breaking) Control over which types custom scalars deserialize to is given to the user: you now have to provide type aliases for the custom scalars in the scope of the struct under derive.
- (breaking) Support for multi-operations documents. You can select a particular operation by naming the struct under derive after it. In case there is no match, we revert to the current behaviour: select the first operation.
- (breaking) Support arbitrary derives on the generated response types via the
response_derivesoption on thegraphqlattribute. If you were relying on theDebugimpl on generated structs before, you need to addresponse_derives = "Debug"in the#[graphql()]attributes in your structs.
- Fixed codegen of fields with leading underscores - they were ignored, leading to wrong derived types for deserialization.
- Made the CLI dump introspected schemas directly without trying to validate them.
- Implemented support for the
extensionsfield on errors from the June 2018 spec (#64). - Improved documentation crate docs, added doctests and examples
Locationfields on errors were not public.- The field names on input objects were not properly converted between snake and camel case.
serde_jsonis now a dependency, because theextensionsfield on errors can be contain arbitrary JSON.
- Copy documentation from the GraphQL schema to the generated types (including their fields) as normal Rust documentation. Documentation will show up in the generated docs as well as IDEs that support expanding derive macros (which does not include the RLS yet).
- Implement and test deserializing subscription responses. We also try to provide helpful error messages when a subscription query is not valid (i.e. when it has more than one top-level field).
- Support the new top-level errors shape from the June 2018 spec, except for the
extensionsfield (see issue #64).
- The generated
ResponseDatastructs did not convert between snake and camel case.
This is the initial public release in which the library is considered usable.
- Support generating a
Variablesstruct for a given query and schema through a custom derive, corresponding to the expected variables. - Support generating a
ResponseDatastruct for a given query and schema through a custom derive, corresponding to the shape of the expected response. - Various utility traits and structs for working with GraphQL query. This notably does not include code to actually perform the network operations. This may be part of future releases.
- Docs and examples