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.
- Add support for GraphQL’s
extend type
directive - Add support for
graphqls://
schema - Expose
generate_module_token_stream_from_string
to 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_none
andskip_serializing_none
- Fix CI
- The
variables_derives
now trims whitespace from individual derivation traits. - The new
reqwest-rustls
feature works like thereqwest
feature but withrustls
rather thannative-tls
. - Code generated by the
graphql-client
CLI 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
web
feature is dropped. You can now use areqwest::Client
instead of the custom HTTP client. - Allow specifying externally defined enums (thanks @jakmeier)
- Make the derive feature optional (but enabled by default)
--no-ssl
param 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
normalization
attribute, 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_derives
now only applies to responses. Usevariables_derives
for variable structure derives.
- (BREAKING) In the CLI, there was a conflict between the short forms
--output-directory
and--selected-operation
since they were both-o
. After this fix,-o
is 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_web
is now deprecated. The browser client has been moved to thegraphql_client
crate, under theweb
module. It is only available with theweb
feature enabled on thewasm32-unknown-unknown
target.
- In the CLI, both --selected-operation and --output used the -o shorthand. --output now uses -out.
-
The
selected_operation
derive 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
schema
declaration in a schema, the root types will be matched by name (Query
,Mutation
andSubscription
).
- 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
rustfmt
feature). -
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
Rust
prefix on the name of generated items. - (BREAKING) If you don't set
--selected-operation
options 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_derive
to 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
@deprecated
field annotations. You can configure how deprecations are handled via thedeprecated
argument in theGraphQLQuery
derive:#[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
--authorization
flag to pass the contents of anAuthorization
header. 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_derives
are 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-derive
crate was factored out into a newgraphql-client-codegen
crate 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
GraphQL
prefix. 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!)
-
GraphQLError
now implements theDisplay
trait. -
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 calledtype
in a GraphQL query will become atype_
field in the generated struct. Thanks to @scrogson! -
The
operationName
field 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_derives
option on thegraphql
attribute. If you were relying on theDebug
impl 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
extensions
field on errors from the June 2018 spec (#64). - Improved documentation crate docs, added doctests and examples
Location
fields on errors were not public.- The field names on input objects were not properly converted between snake and camel case.
serde_json
is now a dependency, because theextensions
field 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
extensions
field (see issue #64).
- The generated
ResponseData
structs did not convert between snake and camel case.
This is the initial public release in which the library is considered usable.
- Support generating a
Variables
struct for a given query and schema through a custom derive, corresponding to the expected variables. - Support generating a
ResponseData
struct 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