Showing preview only (423K chars total). Download the full file or copy to clipboard to get everything.
Repository: davidpdrsn/juniper-from-schema
Branch: master
Commit: 90f1e3317370
Files: 141
Total size: 380.7 KB
Directory structure:
gitextract_45z7vqcr/
├── .github/
│ └── workflows/
│ └── ci.yml
├── .gitignore
├── CHANGELOG.md
├── Cargo.toml
├── LICENSE
├── README.md
├── bin/
│ ├── release
│ └── run_all_examples
├── generate-subscription-tests/
│ ├── Cargo.toml
│ ├── generated_files/
│ │ └── .gitkeep
│ └── src/
│ └── main.rs
├── juniper-from-schema/
│ ├── Cargo.toml
│ ├── README.md
│ ├── examples/
│ │ ├── async.rs
│ │ ├── default_argument_values.rs
│ │ ├── enumeration_types.rs
│ │ ├── hello_world.rs
│ │ ├── input_types.rs
│ │ ├── interface.rs
│ │ ├── query_trails.rs
│ │ ├── subscription.rs
│ │ └── union_types.rs
│ ├── src/
│ │ └── lib.rs
│ └── tests/
│ ├── compile_fail/
│ │ ├── docs_on_special_case_scalars.rs
│ │ ├── docs_on_special_case_scalars.stderr
│ │ ├── invalid_as_ref_type.rs
│ │ ├── invalid_as_ref_type.stderr
│ │ ├── invalid_date_time_scalar_directive.rs
│ │ ├── invalid_date_time_scalar_directive.stderr
│ │ ├── invalid_juniper_directive_definition.rs
│ │ ├── invalid_juniper_directive_definition.stderr
│ │ ├── invalid_stream_return_type.rs
│ │ ├── invalid_stream_return_type.stderr
│ │ ├── scalar_with_built_in_name.rs
│ │ ├── scalar_with_built_in_name.stderr
│ │ ├── snake_cased_fields_on_input_object_types.rs
│ │ ├── snake_cased_fields_on_input_object_types.stderr
│ │ ├── snake_cased_fields_on_interfaces.rs
│ │ ├── snake_cased_fields_on_interfaces.stderr
│ │ ├── snake_cased_fields_on_types.rs
│ │ ├── snake_cased_fields_on_types.stderr
│ │ ├── unknown_directive.rs
│ │ ├── unknown_directive.stderr
│ │ ├── unsupported_config.rs
│ │ ├── unsupported_config.stderr
│ │ ├── uppercase_uuid.rs
│ │ └── uppercase_uuid.stderr
│ ├── compile_pass/
│ │ ├── async.rs
│ │ ├── async_as_ref.rs
│ │ ├── async_field_returning_type.rs
│ │ ├── async_returning_reference.rs
│ │ ├── correct_executor_signature.rs
│ │ ├── custom_scalar.rs
│ │ ├── customizing_context_name.rs
│ │ ├── customizing_the_error_type.rs
│ │ ├── dates_and_times.rs
│ │ ├── directive_definitions_are_allowed.rs
│ │ ├── empty_mutations.rs
│ │ ├── enums.rs
│ │ ├── field_args.rs
│ │ ├── infallible_directive.rs
│ │ ├── input_object.rs
│ │ ├── input_object_clone.rs
│ │ ├── input_objects_have_public_fields.rs
│ │ ├── naive_date_time.rs
│ │ ├── non_null_list_non_null_items.rs
│ │ ├── non_null_list_nullable_items.rs
│ │ ├── nullable_list_non_null_items.rs
│ │ ├── nullable_list_nullable_items.rs
│ │ ├── ownership_attributes.rs
│ │ ├── query_trail.rs
│ │ ├── query_trail_methods_for_interfaces.rs
│ │ ├── query_trail_methods_for_union_types.rs
│ │ ├── returning_references.rs
│ │ ├── setup.rs
│ │ ├── simple_non_null_scalars.rs
│ │ ├── simple_nullable_scalars.rs
│ │ ├── url.rs
│ │ ├── uuid.rs
│ │ └── valid_juniper_directive_definition.rs
│ ├── converting_query_trails_test.rs
│ ├── default_argument_values_test.rs
│ ├── doc_test.rs
│ ├── end_to_end_test.rs
│ ├── launchpad.rs
│ ├── query_trail_arguments.rs
│ ├── schemas/
│ │ ├── complex_schema.graphql
│ │ ├── customizing_context_name.graphql
│ │ ├── doc_schema.graphql
│ │ ├── doc_test.graphql
│ │ ├── original_complex.graphql
│ │ ├── returning_references.graphql
│ │ └── very_simple_schema.graphql
│ ├── subscriptions/
│ │ ├── fail/
│ │ │ ├── stream_item_type_not_in_subscription_field.rs
│ │ │ ├── stream_item_type_not_in_subscription_field.stderr
│ │ │ ├── stream_type_not_in_subscription_field.rs
│ │ │ ├── stream_type_not_in_subscription_field.stderr
│ │ │ ├── subscriptions_cannot_implement_interfaces.rs
│ │ │ └── subscriptions_cannot_implement_interfaces.stderr
│ │ ├── pass/
│ │ │ ├── ownership_owned_infallible_false_async_false_stream_type_UserStream_stream_item_infallible_false.rs
│ │ │ ├── ownership_owned_infallible_false_async_false_stream_type_UserStream_stream_item_infallible_true.rs
│ │ │ ├── ownership_owned_infallible_false_async_false_stream_type_default_stream_item_infallible_false.rs
│ │ │ ├── ownership_owned_infallible_false_async_false_stream_type_default_stream_item_infallible_true.rs
│ │ │ ├── ownership_owned_infallible_false_async_true_stream_type_UserStream_stream_item_infallible_false.rs
│ │ │ ├── ownership_owned_infallible_false_async_true_stream_type_UserStream_stream_item_infallible_true.rs
│ │ │ ├── ownership_owned_infallible_false_async_true_stream_type_default_stream_item_infallible_false.rs
│ │ │ ├── ownership_owned_infallible_false_async_true_stream_type_default_stream_item_infallible_true.rs
│ │ │ ├── ownership_owned_infallible_true_async_false_stream_type_UserStream_stream_item_infallible_false.rs
│ │ │ ├── ownership_owned_infallible_true_async_false_stream_type_UserStream_stream_item_infallible_true.rs
│ │ │ ├── ownership_owned_infallible_true_async_false_stream_type_default_stream_item_infallible_false.rs
│ │ │ ├── ownership_owned_infallible_true_async_false_stream_type_default_stream_item_infallible_true.rs
│ │ │ ├── ownership_owned_infallible_true_async_true_stream_type_UserStream_stream_item_infallible_false.rs
│ │ │ ├── ownership_owned_infallible_true_async_true_stream_type_UserStream_stream_item_infallible_true.rs
│ │ │ ├── ownership_owned_infallible_true_async_true_stream_type_default_stream_item_infallible_false.rs
│ │ │ └── ownership_owned_infallible_true_async_true_stream_type_default_stream_item_infallible_true.rs
│ │ └── subscription_setup.rs
│ └── version-numbers.rs
├── juniper-from-schema-build/
│ ├── Cargo.toml
│ └── src/
│ └── lib.rs
├── juniper-from-schema-build-tests/
│ ├── basic/
│ │ ├── Cargo.toml
│ │ ├── build.rs
│ │ └── src/
│ │ └── lib.rs
│ └── file/
│ ├── Cargo.toml
│ ├── build.rs
│ ├── schema.graphql
│ └── src/
│ └── lib.rs
├── juniper-from-schema-code-gen/
│ ├── Cargo.toml
│ └── src/
│ ├── ast_pass/
│ │ ├── code_gen_pass/
│ │ │ ├── gen_query_trails.rs
│ │ │ └── mod.rs
│ │ ├── directive_parsing.rs
│ │ ├── error.rs
│ │ ├── mod.rs
│ │ ├── schema_visitor.rs
│ │ └── validations.rs
│ └── lib.rs
├── juniper-from-schema-proc-macro/
│ ├── Cargo.toml
│ ├── README.md
│ ├── src/
│ │ ├── lib.rs
│ │ └── parse_input.rs
│ └── tests/
│ └── version-numbers.rs
└── rustfmt.toml
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/workflows/ci.yml
================================================
name: CI
on: [push]
jobs:
check-formatting:
name: Check formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check formatting
run: cargo +stable fmt -- --check
test-on-nightly:
name: Test on nightly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# caching build artifacts
- name: Cache cargo registry
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Use nightly
run: rustup override set nightly && rustup show
- name: Run tests
run: cargo test --all
- name: Run examples
run: bin/run_all_examples
test-on-stable:
name: Test on stable
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# caching build artifacts
- name: Cache cargo registry
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Use stable
run: rustup override set stable && rustup show
- name: Run tests
run: cargo test --all
- name: Run examples
run: bin/run_all_examples
================================================
FILE: .gitignore
================================================
/target
**/*.rs.bk
Cargo.lock
/tmp
generate-subscription-tests/generated_files/*.rs
================================================
FILE: CHANGELOG.md
================================================
# Change Log
All user visible changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/), as described
for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/text/1105-api-evolution.md)
## Unreleased
- Async resolvers are now supported (requires juniper 0.15).
- Subscriptions are now supported (requires juniper 0.15).
- Give nice error if you declare custom scalar with same name as built-in.
- Re-export juniper from juniper-from-schema to make sure we're always using the same version.
- Support generating code from `build.rs` instead of a procedural macro. See the docs for more details.
#### Breaking changes
The `executor` argument in `field_*` methods now requires two lifetime arguments:
```rust
fn field_hello_world<'r, 'a>(
&self,
executor: &Executor<'r, 'a, Context>
) -> FieldResult<String> {
todo!()
}
```
This is due to breaking change in juniper. However with a recent version of Rust you can actually skip declaring the lifetimes at all:
```rust
fn field_hello_world(
&self,
executor: &Executor<Context>
) -> FieldResult<String> {
todo!()
}
```
## [0.5.2] - 2020-02-19
- Remove `MakeQueryTrail` trait. This is not a breaking change since user's shouldn't be using it.
- Require the UUID scalar type to be named `Uuid`. This is to remain consistent with the uuid crate. This is not considered a breaking change since it fixes a bug in code generation with inconsistent case. See [#104](https://github.com/davidpdrsn/juniper-from-schema/issues/104).
- Add derive `Clone` to input types. See [#110](https://github.com/davidpdrsn/juniper-from-schema/issues/110)
- Support all directive definitions in schema but require specific definition for `@juniper`. See the docs for valid definiton of `@juniper`. juniper-from-schema doesn't require you to define `@juniper` in your schema, but some other external tools might.
## [0.5.1] - 2019-11-14
- Support making fields infallible with `@juniper(infallible: true)`.
- Make sure fields on input object structs are in fact public.
## [0.5.0] - 2019-10-17
#### Breaking changes
- Remove the second lifetime from generated structs for field arguments. Turns out `'a` from `QueryTrail<'a, _, _>` is all we need.
- The `DateTime` scalar has been renamed to `DateTimeUtc` to clearly communicate the name Juniper gives it.
## [0.4.2] - 2019-10-16
- Add support for inspecting arguments to `QueryTrail`. See docs for more info. [#83](https://github.com/davidpdrsn/juniper-from-schema/pull/83).
## [0.4.1] - 2019-10-16
### Fixed
- Correctly trigger rebuild of Rust schema if only GraphQL schema changed when using `graphql_schema_from_file!`.
## [0.4.0] - 2019-10-05
### Added
- Support converting `QueryTrail`s for interfaces or unions into `QueryTrail`s for implementors of those interfaces or unions. This makes it possible to use [juniper-eager-loading](https://crates.io/crates/juniper-eager-loading) with interface or union types. [#63](https://github.com/davidpdrsn/juniper-from-schema/pull/63)
### Changed
- The `QueryTrail` type is now part of this library rather than being emitted as part of the generated code. This was done so other libraries could make sure of the type. If you're getting errors about missing methods adding `use crate::graphql_schema::query_trails::*` to you module should fix it. [#82](https://github.com/davidpdrsn/juniper-from-schema/pull/82)
## [0.3.2] - 2019-09-30
### Added
- Juniper 0.14 support.
## [0.3.1] - 2019-09-24
### Added
- Support customizing the name of the context type. [#66](https://github.com/davidpdrsn/juniper-from-schema/pull/66)
- Improve documentation of special case scalar types.
- Implement common traits for generated scalar types.
- Support converting `DateTime` into `chrono::NaiveDateTime` for those who don't care about time zones. The behavior can be customized with the `@juniper(with_time_zone: true|false)` directive on the scalar definition.
### Changed
- Special case scalars `Date`, `DateTime`, `Uuid`, and `Url` no longer support descriptions in the GraphQL schema. See [#69](https://github.com/davidpdrsn/juniper-from-schema/pull/69) for more details.
### Fixed
- Fix support for special case [`Uuid`](https://crates.io/crates/uuid) and [`Url`](https://crates.io/crates/url) scalars. [#69](https://github.com/davidpdrsn/juniper-from-schema/pull/69)
- Removed some deprecation warnings related to scalar types. [#78](https://github.com/davidpdrsn/juniper-from-schema/pull/78)
- Don't deprecate enum variants in Rust code when marked as deprecated in the schema.
## [0.3.0] - 2019-06-18
- Will now fail to compile if you schema contains field names in snake_case. [#47](https://github.com/davidpdrsn/juniper-from-schema/issues/47)
## [0.2.3] - 2019-06-15
### Fixed
- Fix `QueryTrail` walk methods always returning `false` for fields defined using snake_case in the schema. [#46](https://github.com/davidpdrsn/juniper-from-schema/pull/46)
## [0.2.2] - 2019-06-10
### Added
- Add support for "as_ref" ownership types such as `FieldResult<Option<&T>>`.
## [0.2.1] - 2019-05-24
### Changed
- Break crate into two: One that exposes shared types, one that does the code generation. Should not be a breaking change.
## [0.2.0] - 2019-05-08
### Changed
- Replace the magic `#[ownership(owned)]` comment with a schema directive.
## [0.1.7] - 2019-05-07
### Added
- Support default values for input objects.
- Support `deprecated` directives on fields and enum values.
### Fixed
- Ensure enum variants used for default values exist. This would previously be a run time error. It is now a compile time error.
## [0.1.6] - 2019-05-04
### Added
- Much better error messages. Basically a rip-off of Rust's compiler errors.
### Changed
- The `ID` GraphQL type now gets generated into `juniper::ID` instead of a custom newtype wrapper. This is a breaking change but should be straight forward to fix.
### Fixed
- Correctly panic if schema contains unsupported features such as directives or a subscription type.
- Correctly generate docs for all types.
- Fix compile error when using custom scalar.
## [0.1.5] - 2019-04-26
### Added
- Make default argument values work for floats, integers, strings, booleans, enumerations, and lists (of supported types). Objects, variables, and nulls are not supported.
### Fixed
- Field methods that return enumerations no longer get `QueryTrails`. You couldn't really do anything with them since enumerations cannot contain data.
- Schemes that don't contain a root mutation type now doesn't fail to compile. It would use `()` for the context, when it should have used `Context`.
## [0.1.4] - 2019-02-16
### Fixed
- Make `graphql_schema_from_file!` look from same folder as your `Cargo.toml`. This fixes issues with finding the schema within a [workspace](https://doc.rust-lang.org/book/second-edition/ch14-03-cargo-workspaces.html) project. Should not be a breaking change.
- Added missing `juniper::` qualifications for generated code that referenced `Executor`.
- Many documentation improvements, including:
- Table of contents
- Description of how to customize the error type
- Clearer example code by removing `use juniper::*`
- Description of how `QueryTrail` works for `Vec<T>` and `Option<T>`
- Describe how to view the generated code
- Several typo fixes
## [0.1.3] - 2019-02-01
### Fixed
- `QueryTrail` methods now generated for union types.
## [0.1.2] - 2019-01-14
### Fixed
- `QueryTrail` methods now generated for interface types.
## [0.1.1] - 2018-12-21
Just fixed broken homepage link on crates.io
## 0.1.0 - 2018-12-21
Initial release.
[0.5.2]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.5.1...0.5.2
[0.5.1]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.5.0...0.5.1
[0.5.0]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.4.2...0.5.0
[0.4.2]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.4.1...0.4.2
[0.4.1]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.4.0...0.4.1
[0.4.0]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.3.2...0.4.0
[0.3.2]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.3.1...0.3.2
[0.3.1]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.3.0...0.3.1
[0.3.0]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.2.3...0.3.0
[0.2.3]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.2.2...0.2.3
[0.2.2]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.2.1...0.2.2
[0.2.1]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.2.0...0.2.1
[0.2.0]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.1.7...0.2.0
[0.1.7]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.1.6...0.1.7
[0.1.6]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.1.5...0.1.6
[0.1.5]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.1.4...0.1.5
[0.1.4]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.1.3...0.1.4
[0.1.3]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.1.2...0.1.3
[0.1.2]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.1.1...0.1.2
[0.1.1]: https://github.com/davidpdrsn/juniper-from-schema/compare/0.1.0...0.1.1
================================================
FILE: Cargo.toml
================================================
[workspace]
members = [
"juniper-from-schema",
"juniper-from-schema-proc-macro",
"juniper-from-schema-code-gen",
"juniper-from-schema-build",
# Tests
"juniper-from-schema-build-tests/basic",
"juniper-from-schema-build-tests/file",
]
exclude = ["generate-subscription-tests"]
================================================
FILE: LICENSE
================================================
MIT License Copyright (c) 2020 David Grynnerup Pedersen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
================================================
FILE: README.md
================================================
# [juniper-from-schema](https://crates.io/crates/juniper-from-schema)

[](https://crates.io/crates/juniper-from-schema)
[](https://docs.rs/juniper-from-schema)
This library contains a procedural macro that reads a GraphQL schema file, and generates the
corresponding [Juniper](https://crates.io/crates/juniper) [macro calls]. This means you can
have a real schema file and be guaranteed that it matches your Rust implementation. It also
removes most of the boilerplate involved in using Juniper.
[macro calls]: https://graphql-rust.github.io/types/objects/complex_fields.html
# Looking for juniper 0.15 support?
The version of juniper-from-schema that is released on crates.io (0.5.2) doesn't support juniper 0.15. However the master branch does! So you will have to use a git dependency for now. We plan to do an official release soon. Follow [this](https://github.com/davidpdrsn/juniper-from-schema/milestone/1) milestone to see whats left.
# Example
Imagine you have a GraphQL schema like this:
```graphql
schema {
query: Query
}
type Query {
helloWorld(name: String!): String! @juniper(ownership: "owned")
}
```
That can be implemented like so:
```rust
use juniper_from_schema::graphql_schema_from_file;
// This is the important line
graphql_schema_from_file!("readme_schema.graphql");
pub struct Context;
impl juniper::Context for Context {}
pub struct Query;
// This trait is generated by `graphql_schema_from_file!` based on the schema
impl QueryFields for Query {
fn field_hello_world(
&self,
_executor: &juniper::Executor<Context>,
name: String,
) -> juniper::FieldResult<String> {
Ok(format!("Hello, {}!", name))
}
}
fn main() {
let ctx = Context;
let query = "query { helloWorld(name: \"Ferris\") }";
let (result, errors) = juniper::execute_sync(
query,
None,
&Schema::new(Query, juniper::EmptyMutation::new()),
&juniper::Variables::new(),
&ctx,
)
.unwrap();
assert_eq!(errors.len(), 0);
assert_eq!(
result
.as_object_value()
.unwrap()
.get_field_value("helloWorld")
.unwrap()
.as_scalar_value::<String>()
.unwrap(),
"Hello, Ferris!",
);
}
```
See the [crate documentation](https://docs.rs/juniper-from-schema/) for a usage examples and more info.
# N+1s
If you're having issues with N+1 query bugs consider using [juniper-eager-loading](https://crates.io/crates/juniper-eager-loading). It was built to integrate seamlessly with juniper-from-schema.
# Development
## If you're seeing `No such file or directory (os error 2)` when running the tests
This might be caused by setting `CARGO_TARGET_DIR`. Setting that env var changes the directory the [trybuild](https://crates.io/crates/trybuild) tests are run from which means all the paths to the test schemas no longer match. The only workaround is to unset `CARGO_TARGET_DIR` when working on juniper-from-schema. I recommend [direnv](https://github.com/direnv/direnv) to unset the env var only this directory and not globally.
================================================
FILE: bin/release
================================================
#!/bin/bash
set -e
cd ./juniper-from-schema-code-gen
cargo release --no-dev-version
cd ./juniper-from-schema-build
cargo release --no-dev-version
cd ./juniper-from-schema-proc-macro
cargo release --no-dev-version
cd ../juniper-from-schema
cargo release --no-dev-version
================================================
FILE: bin/run_all_examples
================================================
#!/bin/bash
set -e
main() {
cd juniper-from-schema
find examples -name "*.rs" |
while read f; do cargo run --example "`echo $f |
sed "s/examples\///g" |
sed "s/\.rs//g"`"; done
}
main
================================================
FILE: generate-subscription-tests/Cargo.toml
================================================
[package]
name = "all-subscription-options"
version = "0.1.0"
authors = ["David Pedersen <david.pdrsn@gmail.com>"]
edition = "2018"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
================================================
FILE: generate-subscription-tests/generated_files/.gitkeep
================================================
================================================
FILE: generate-subscription-tests/src/main.rs
================================================
// This crate is used to generate the tests you'll find in "juniper-from-schema/tests/subscriptions."
//
// There are quite a few ways in which directives interact so we generate the tests to make sure we
// cover all the cases.
//
// The generated files will be placed in
// "juniper-from-schema/generate-subscription-tests/generated_files" so currently you manually have
// to move them into "juniper-from-schema/tests/subscriptions"
fn main() {
let combinations = Ownership::all()
.flat_map(|ownership| {
Infallible::all().flat_map(move |infallible| {
Async::all().flat_map(move |async_| {
StreamType::all().flat_map(move |stream_type| {
StreamItemInfallible::all().map(move |stream_item_infallible| {
(
ownership,
infallible,
async_,
stream_type,
stream_item_infallible,
)
})
})
})
})
})
.collect::<Vec<(
Ownership,
Infallible,
Async,
StreamType,
StreamItemInfallible,
)>>();
for (ownership, infallible, async_, stream_type, stream_item_infallible) in combinations {
let args = vec![
ownership.to_string(),
infallible.to_string(),
async_.to_string(),
stream_type.to_string(),
stream_item_infallible.to_string(),
]
.into_iter()
.filter_map(|item| item)
.collect::<Vec<_>>()
.join(", ");
let return_type = match (stream_type, infallible, stream_item_infallible, ownership) {
(_, _, _, Ownership::AsRef) => continue,
(_, _, _, Ownership::Borrowed) => continue,
(StreamType::Default, Infallible::True, StreamItemInfallible::True, Ownership::Owned) => {
"BoxStream<User>"
}
(StreamType::Default, Infallible::True, StreamItemInfallible::False, Ownership::Owned) => {
"BoxStream<FieldResult<User>>"
}
(StreamType::Default, Infallible::False, StreamItemInfallible::True, Ownership::Owned) => {
"FieldResult<BoxStream<User>>"
}
(StreamType::Default, Infallible::False, StreamItemInfallible::False, Ownership::Owned) => {
"FieldResult<BoxStream<FieldResult<User>>>"
}
(StreamType::Custom, Infallible::True, _, _) => "UserStream",
(StreamType::Custom, Infallible::False, _, _) => "FieldResult<UserStream>",
};
let async_trait = match async_ {
Async::True => "#[async_trait]\n",
Async::False => "",
};
let async_str = match async_ {
Async::True => "async ",
Async::False => "",
};
let stream_item_ty = match stream_item_infallible {
StreamItemInfallible::True => "User",
StreamItemInfallible::False => "FieldResult<User>",
};
let user_stream = if return_type.contains("UserStream") {
format!(r#"pub struct UserStream;
impl Stream for UserStream {{
type Item = {};
fn poll_next(
self: std::pin::Pin<&mut Self>,
cx: &mut futures::task::Context<'_>,
) -> futures::task::Poll<Option<Self::Item>> {{
todo!()
}}
}}"#, stream_item_ty)
} else {
String::new()
};
let body = "todo!()";
let code = format!(
r##"#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../subscription_setup.rs");
juniper_from_schema::graphql_schema! {{
type Query {{
ping: Boolean!
}}
type Subscription {{
users: User! @juniper({args})
}}
type User {{
id: ID!
name: String!
}}
schema {{
query: Query
subscription: Subscription
}}
}}
{async_trait}impl SubscriptionFields for Subscription {{
{async}fn field_users<'s, 'r, 'a>(
&'s self,
_: &Executor<'r, 'a, Context>,
_: &QueryTrail<'r, User, Walked>,
) -> {type} {{
{body}
}}
}}
{user_stream}"##,
args = args, type = return_type, body = body, async = async_str, async_trait = async_trait, user_stream = user_stream
);
let file_name = format!(
"generated_files/{}_{}_{}_{}_{}_{}_{}_{}_{}_{}.rs",
ownership.name(),
ownership.variant().unwrap_or("default").replace('"', ""),
infallible.name(),
infallible.variant().unwrap_or("default"),
async_.name(),
async_.variant().unwrap_or("default"),
stream_type.name(),
stream_type.variant().unwrap_or("default").replace('"', ""),
stream_item_infallible.name(),
stream_item_infallible.variant().unwrap_or("default"),
);
std::fs::write(file_name, code.as_bytes()).unwrap();
}
}
macro_rules! def_enum {
(
($name:ident, $name_str:expr), [$( ($variant:ident, $variant_str:expr) ),* $(,)?]
) => {
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
enum $name {
$($variant),*
}
impl $name {
fn all() -> impl Iterator<Item = Self> {
vec![ $($name::$variant),* ].into_iter()
}
fn name(&self) -> &'static str {
match self {
$(
$name::$variant => $name_str,
)*
}
}
fn variant(&self) -> Option<&'static str> {
match self {
$(
$name::$variant => $variant_str,
)*
}
}
fn to_string(&self) -> Option<String> {
if let Some(s) = self.variant() {
Some(format!("{}: {}", $name_str, s))
} else {
None
}
}
}
};
}
def_enum!(
(Ownership, "ownership"),
[
(Borrowed, Some("\"borrowed\"")),
(AsRef, Some("\"as_ref\"")),
(Owned, Some("\"owned\""))
]
);
def_enum!(
(Infallible, "infallible"),
[(True, Some("true")), (False, Some("false"))]
);
def_enum!(
(Async, "async"),
[(True, Some("true")), (False, Some("false"))]
);
def_enum!(
(StreamType, "stream_type"),
[(Default, None), (Custom, Some("\"UserStream\""))]
);
def_enum!(
(StreamItemInfallible, "stream_item_infallible"),
[(True, Some("true")), (False, Some("false"))]
);
================================================
FILE: juniper-from-schema/Cargo.toml
================================================
[package]
version = "0.5.2"
authors = ["David Pedersen <david.pdrsn@gmail.com>"]
categories = ["web-programming"]
description = "Generate Juniper code from you GraphQL schema"
documentation = "https://docs.rs/juniper-from-schema"
edition = "2018"
homepage = "https://github.com/davidpdrsn/juniper-from-schema"
keywords = ["web", "graphql", "juniper"]
license = "MIT"
name = "juniper-from-schema"
readme = "README.md"
repository = "https://github.com/davidpdrsn/juniper-from-schema.git"
[dependencies]
juniper-from-schema-proc-macro = { version = "0.5.2", path = "../juniper-from-schema-proc-macro" }
juniper = "0.15"
futures = "0.3"
[dev_dependencies]
serde_json = "1"
assert-json-diff = "0.2"
maplit = "1"
version-sync = "0.8"
trybuild = "1"
rustversion = "0.1"
uuid = { version = "0.8", features = ["v4"] }
url = "2"
chrono = "0.4"
async-trait = "0.1"
tokio = { version = "0.2", features = ["sync", "stream"] }
================================================
FILE: juniper-from-schema/README.md
================================================
# [juniper-from-schema](https://crates.io/crates/juniper-from-schema)
[](https://crates.io/crates/juniper-from-schema)
[](https://docs.rs/juniper-from-schema)
This library contains a procedural macro that reads a GraphQL schema file, and generates the
corresponding [Juniper](https://crates.io/crates/juniper) [macro calls]. This means you can
have a real schema file and be guaranteed that it matches your Rust implementation. It also
removes most of the boilerplate involved in using Juniper.
[macro calls]: https://graphql-rust.github.io/types/objects/complex_fields.html
See the [crate documentation](https://docs.rs/juniper-from-schema/) for a usage examples and more info.
================================================
FILE: juniper-from-schema/examples/async.rs
================================================
#![allow(dead_code, unused_variables, unused_imports)]
use async_trait::async_trait;
use juniper::*;
use juniper_from_schema::graphql_schema;
graphql_schema! {
schema {
query: Query
}
type Query {
findTweet(id: ID!): [Tweet!]! @juniper(ownership: "owned", async: true)
}
type Tweet {
id: ID!
text: String!
}
}
pub struct Context;
impl juniper::Context for Context {}
pub struct Tweet {
id: ID,
text: String,
}
impl TweetFields for Tweet {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
unimplemented!()
}
fn field_text(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
pub struct Query;
#[async_trait]
impl QueryFields for Query {
async fn field_find_tweet<'s, 'r, 'a>(
&'s self,
executor: &Executor<'r, 'a, Context>,
trail: &QueryTrail<'r, Tweet, Walked>,
id: ID,
) -> FieldResult<Vec<Tweet>> {
let tweets = vec![Tweet {
id,
text: String::from("Hello, World!"),
}];
Ok(tweets)
}
}
fn main() {}
================================================
FILE: juniper-from-schema/examples/default_argument_values.rs
================================================
#![allow(dead_code, unused_variables, unused_imports)]
use juniper::*;
use juniper_from_schema::graphql_schema;
graphql_schema! {
schema {
query: Query
}
enum Status {
PUBLISHED
UNPUBLISHED
}
type Query {
allPosts(status: Status = PUBLISHED): [Post!]! @juniper(ownership: "owned")
}
type Post {
id: ID!
}
}
pub struct Context;
impl juniper::Context for Context {}
pub struct Post {
id: ID,
}
impl PostFields for Post {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
Ok(&self.id)
}
}
pub struct Query;
impl QueryFields for Query {
fn field_all_posts(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Post, Walked>,
status: Status,
) -> FieldResult<Vec<Post>> {
// `status` will be `Status::Published` if not given in the query
match status {
Status::Published => unimplemented!("find published posts"),
Status::Unpublished => unimplemented!("find unpublished posts"),
}
}
}
fn main() {}
================================================
FILE: juniper-from-schema/examples/enumeration_types.rs
================================================
#![allow(dead_code, unused_variables, unused_imports)]
use juniper::*;
use juniper_from_schema::graphql_schema;
graphql_schema! {
schema {
query: Query
}
enum Status {
PUBLISHED
UNPUBLISHED
}
type Query {
allPosts(status: Status!): [Post!]! @juniper(ownership: "owned")
}
type Post {
id: ID!
}
}
fn main() {}
pub struct Context;
impl juniper::Context for Context {}
pub struct Post {
id: ID,
}
impl PostFields for Post {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
Ok(&self.id)
}
}
pub struct Query;
impl QueryFields for Query {
fn field_all_posts(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Post, Walked>,
status: Status,
) -> FieldResult<Vec<Post>> {
match status {
Status::Published => unimplemented!("find published posts"),
Status::Unpublished => unimplemented!("find unpublished posts"),
}
}
}
================================================
FILE: juniper-from-schema/examples/hello_world.rs
================================================
#![allow(dead_code, unused_variables, unused_imports)]
use juniper::*;
use juniper_from_schema::graphql_schema;
// This is the important line
graphql_schema! {
schema {
query: Query
mutation: Mutation
}
type Query {
// The directive makes the return value `FieldResult<String>`
// rather than the default `FieldResult<&String>`
helloWorld(name: String!): String! @juniper(ownership: "owned")
}
type Mutation {
noop: Boolean!
}
}
pub struct Context;
impl juniper::Context for Context {}
pub struct Query;
impl QueryFields for Query {
fn field_hello_world(&self, executor: &Executor<Context>, name: String) -> FieldResult<String> {
Ok(format!("Hello, {}!", name))
}
}
pub struct Mutation;
impl MutationFields for Mutation {
fn field_noop(&self, executor: &Executor<Context>) -> FieldResult<&bool> {
Ok(&true)
}
}
fn main() {
let ctx = Context;
let query = "query { helloWorld(name: \"Ferris\") }";
let (result, errors) = juniper::execute_sync(
query,
None,
&Schema::new(Query, Mutation, juniper::EmptySubscription::new()),
&Variables::new(),
&ctx,
)
.unwrap();
assert_eq!(errors.len(), 0);
assert_eq!(
result
.as_object_value()
.unwrap()
.get_field_value("helloWorld")
.unwrap()
.as_scalar_value::<String>()
.unwrap(),
"Hello, Ferris!",
);
}
================================================
FILE: juniper-from-schema/examples/input_types.rs
================================================
#![allow(dead_code, unused_variables, unused_imports)]
use juniper::*;
use juniper_from_schema::graphql_schema;
graphql_schema! {
schema {
query: Query
mutation: Mutation
}
type Mutation {
createPost(input: CreatePost!): Post @juniper(ownership: "owned")
}
input CreatePost {
title: String!
}
type Post {
id: ID!
title: String!
}
type Query { noop: Boolean! }
}
fn main() {}
pub struct Context;
impl juniper::Context for Context {}
pub struct Post {
id: ID,
}
impl PostFields for Post {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
unimplemented!()
}
fn field_title(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
pub struct Query;
impl QueryFields for Query {
fn field_noop(&self, executor: &Executor<Context>) -> FieldResult<&bool> {
unimplemented!()
}
}
pub struct Mutation;
impl MutationFields for Mutation {
fn field_create_post(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Post, Walked>,
input: CreatePost,
) -> FieldResult<Option<Post>> {
let title: String = input.title;
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/examples/interface.rs
================================================
#![allow(dead_code, unused_variables, unused_imports)]
use juniper::*;
use juniper_from_schema::graphql_schema;
graphql_schema! {
schema {
query: Query
}
type Query {
search(query: String!): [SearchResult!]! @juniper(ownership: "owned")
}
interface SearchResult {
id: ID!
text: String!
}
type Article implements SearchResult {
id: ID!
text: String!
}
type Tweet implements SearchResult {
id: ID!
text: String!
}
}
pub struct Context;
impl juniper::Context for Context {}
pub struct Article {
id: ID,
text: String,
}
impl ArticleFields for Article {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
unimplemented!()
}
fn field_text(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
pub struct Tweet {
id: ID,
text: String,
}
impl TweetFields for Tweet {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
unimplemented!()
}
fn field_text(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
pub struct Query;
impl QueryFields for Query {
fn field_search(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<SearchResult, Walked>,
query: String,
) -> FieldResult<Vec<SearchResult>> {
let article: Article = Article {
id: ID::new("1"),
text: "Business".to_string(),
};
let tweet: Tweet = Tweet {
id: ID::new("2"),
text: "1 weird tip".to_string(),
};
let posts = vec![SearchResult::from(article), SearchResult::from(tweet)];
Ok(posts)
}
}
fn main() {}
================================================
FILE: juniper-from-schema/examples/query_trails.rs
================================================
#![allow(clippy::redundant_pattern_matching)]
#![allow(dead_code, unused_variables, unused_imports)]
use juniper::*;
use juniper_from_schema::graphql_schema;
fn main() {}
pub struct Context;
impl juniper::Context for Context {}
graphql_schema! {
schema {
query: Query
}
type Query {
allPosts: [Post!]! @juniper(ownership: "owned")
}
type Post {
id: Int!
author: User!
}
type User {
id: Int!
}
}
pub struct Query;
impl QueryFields for Query {
fn field_all_posts(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Post, Walked>,
) -> FieldResult<Vec<Post>> {
// Check if the query includes the author
if let Some(_) = trail.author().walk() {
// Somehow preload the users to avoid N+1 query bugs
// Exactly how to do this depends on your setup
}
// Normally this would come from the database
let post = Post {
id: 1,
author: User { id: 1 },
};
Ok(vec![post])
}
}
pub struct Post {
id: i32,
author: User,
}
impl PostFields for Post {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
Ok(&self.id)
}
fn field_author(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<User, Walked>,
) -> FieldResult<&User> {
Ok(&self.author)
}
}
pub struct User {
id: i32,
}
impl UserFields for User {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
Ok(&self.id)
}
}
================================================
FILE: juniper-from-schema/examples/subscription.rs
================================================
#![allow(dead_code, unused_variables, unused_imports)]
use async_trait::async_trait;
use futures::stream::{Stream, StreamExt};
use juniper::*;
use juniper_from_schema::graphql_schema;
use std::pin::Pin;
use tokio::sync::broadcast::Sender;
graphql_schema! {
schema {
query: Query
subscription: Subscription
}
type Query {
// Query must have at least one field
ping: Boolean!
}
type Subscription {
tweets: Tweet! @juniper(ownership: "owned", infallible: true, stream_item_infallible: false)
}
type Tweet {
id: ID!
}
}
pub struct Context {
tx: Sender<Tweet>,
}
impl juniper::Context for Context {}
#[derive(Clone)]
pub struct Tweet {
id: ID,
text: String,
}
impl TweetFields for Tweet {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
unimplemented!()
}
}
pub struct Subscription;
impl SubscriptionFields for Subscription {
fn field_tweets(
&self,
executor: &Executor<Context>,
_: &QueryTrail<Tweet, Walked>,
) -> Pin<Box<dyn Stream<Item = FieldResult<Tweet>> + Send>> {
let ctx = executor.context();
let receiver = ctx.tx.subscribe();
let stream = receiver.into_stream().map(|item| item.map_err(From::from));
Box::pin(stream)
}
}
pub struct Query;
#[async_trait]
impl QueryFields for Query {
fn field_ping(&self, executor: &Executor<Context>) -> FieldResult<&bool> {
todo!()
}
}
fn main() {}
================================================
FILE: juniper-from-schema/examples/union_types.rs
================================================
#![allow(dead_code, unused_variables, unused_imports)]
use juniper::*;
use juniper_from_schema::graphql_schema;
graphql_schema! {
schema {
query: Query
}
type Query {
search(query: String!): [SearchResult!]! @juniper(ownership: "owned")
}
union SearchResult = Article | Tweet
type Article {
id: ID!
text: String!
}
type Tweet {
id: ID!
text: String!
}
}
pub struct Context;
impl juniper::Context for Context {}
pub struct Article {
id: ID,
text: String,
}
impl ArticleFields for Article {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
unimplemented!()
}
fn field_text(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
pub struct Tweet {
id: ID,
text: String,
}
impl TweetFields for Tweet {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
unimplemented!()
}
fn field_text(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
pub struct Query;
impl QueryFields for Query {
fn field_search(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<SearchResult, Walked>,
query: String,
) -> FieldResult<Vec<SearchResult>> {
let article: Article = Article {
id: ID::new("1"),
text: "Business".to_string(),
};
let tweet: Tweet = Tweet {
id: ID::new("2"),
text: "1 weird tip".to_string(),
};
let posts = vec![SearchResult::from(article), SearchResult::from(tweet)];
Ok(posts)
}
}
fn main() {}
================================================
FILE: juniper-from-schema/src/lib.rs
================================================
//! This library contains a procedural macro that reads a GraphQL schema file, and generates the
//! corresponding [Juniper](https://crates.io/crates/juniper) [macro calls]. This means you can
//! have a real schema file and be guaranteed that it matches your Rust implementation. It also
//! removes most of the boilerplate involved in using Juniper.
//!
//! [macro calls]: https://graphql-rust.github.io/types/objects/complex_fields.html
//!
//! # Table of contents
//!
//! - [Example](#example)
//! - [Example web app](#example-web-app)
//! - [Supported juniper versions](#supported-juniper-versions)
//! - [GraphQL features](#graphql-features)
//! - [The `ID` type](#the-id-type)
//! - [Custom scalar types](#custom-scalar-types)
//! - [Special case scalars](#special-case-scalars)
//! - [Interfaces](#interfaces)
//! - [Union types](#union-types)
//! - [Input objects](#input-objects)
//! - [Enumeration types](#enumeration-types)
//! - [Default argument values](#default-argument-values)
//! - [Subscriptions](#subscriptions)
//! - [Supported schema directives](#supported-schema-directives)
//! - [Definition for `@juniper`](#definition-for-juniper)
//! - [Customizing ownership](#customizing-ownership)
//! - [Infallible fields](#infallible-fields)
//! - [Async resolvers](#async-resolvers)
//! - [GraphQL to Rust types](#graphql-to-rust-types)
//! - [Query trails](#query-trails)
//! - [Abbreviated example](#abbreviated-example)
//! - [Types](#types)
//! - [Downcasting for interface and union `QueryTrail`s](#downcasting-for-interface-and-union-querytrails)
//! - [`QueryTrail`s for fields that take arguments](#querytrails-for-fields-that-take-arguments)
//! - [Customizing the error type](#customizing-the-error-type)
//! - [Customizing the context type](#customizing-the-context-type)
//! - [Inspecting the generated code](#inspecting-the-generated-code)
//! - [Generating code in "build.rs"](#generating-code-in-buildrs)
//!
//! # Example
//!
//! Schema:
//!
//! ```graphql
//! schema {
//! query: Query
//! mutation: Mutation
//! }
//!
//! type Query {
//! // The directive makes the return value `FieldResult<String>`
//! // rather than the default `FieldResult<&String>`
//! helloWorld(name: String!): String! @juniper(ownership: "owned")
//! }
//!
//! type Mutation {
//! noop: Boolean!
//! }
//! ```
//!
//! How you could implement that schema:
//!
//! ```
//! #[macro_use]
//! extern crate juniper;
//!
//! use juniper_from_schema::graphql_schema_from_file;
//!
//! // This is the important line
//! graphql_schema_from_file!("tests/schemas/doc_schema.graphql");
//!
//! pub struct Context;
//! impl juniper::Context for Context {}
//!
//! pub struct Query;
//!
//! impl QueryFields for Query {
//! fn field_hello_world(
//! &self,
//! executor: &juniper::Executor<Context>,
//! name: String,
//! ) -> juniper::FieldResult<String> {
//! Ok(format!("Hello, {}!", name))
//! }
//! }
//!
//! pub struct Mutation;
//!
//! impl MutationFields for Mutation {
//! fn field_noop(&self, executor: &juniper::Executor<Context>) -> juniper::FieldResult<&bool> {
//! Ok(&true)
//! }
//! }
//!
//! fn main() {
//! let ctx = Context;
//!
//! let query = "query { helloWorld(name: \"Ferris\") }";
//!
//! let (result, errors) = juniper::execute_sync(
//! query,
//! None,
//! &Schema::new(Query, Mutation, juniper::EmptySubscription::new()),
//! &juniper::Variables::new(),
//! &ctx,
//! )
//! .unwrap();
//!
//! assert_eq!(errors.len(), 0);
//! assert_eq!(
//! result
//! .as_object_value()
//! .unwrap()
//! .get_field_value("helloWorld")
//! .unwrap()
//! .as_scalar_value::<String>()
//! .unwrap(),
//! "Hello, Ferris!",
//! );
//! }
//! ```
//!
//! # Example web app
//!
//! You can find an example of how to use this library together with [Rocket] and [Diesel] to make
//! a GraphQL web app at <https://github.com/davidpdrsn/graphql-app-example> or an example of how
//! to use this library with [Actix] and [Diesel] at
//! <https://github.com/husseinraoouf/graphql-actix-example>.
//!
//! [Rocket]: https://rocket.rs
//! [Diesel]: http://diesel.rs
//! [Actix]: https://actix.rs/
//!
//! # Supported juniper versions
//!
//! | juniper-from-schema | juniper |
//! |---|---|
//! | 0.6.x | 0.15.x |
//! | 0.5.x | 0.14.x |
//!
//! # GraphQL features
//!
//! The goal of this library is to support as much of GraphQL as Juniper does.
//!
//! Here is the complete list of features:
//!
//! Supported:
//! - Object types including converting lists and non-nulls to Rust types
//! - Custom scalar types including the `ID` type
//! - Interfaces
//! - Unions
//! - Input objects
//! - Enumeration types
//! - Async resolvers
//! - Subscriptions
//!
//! Not supported:
//! - Type extensions
//!
//! ## The `ID` type
//!
//! The `ID` GraphQL type will be generated into [`juniper::ID`].
//!
//! [`juniper::ID`]: https://docs.rs/juniper/latest/juniper/struct.ID.html
//!
//! ## Custom scalar types
//!
//! Custom scalar types will be generated into a newtype wrapper around a `String`. For example:
//!
//! ```graphql
//! scalar Cursor
//! ```
//!
//! Would result in
//!
//! ```
//! pub struct Cursor(pub String);
//! ```
//!
//! ## Special case scalars
//!
//! A couple of scalar names have special meaning. Those are:
//!
//! - `Url` becomes
//! [`url::Url`](https://docs.rs/url/2.1.0/url/struct.Url.html).
//! - `Uuid` becomes
//! [`uuid::Uuid`](https://docs.rs/uuid/0.7.4/uuid/struct.Uuid.html).
//! - `Date` becomes
//! [`chrono::naive::NaiveDate`](https://docs.rs/chrono/0.4.6/chrono/naive/struct.NaiveDate.html).
//! - `DateTimeUtc` becomes [`chrono::DateTime<chrono::offset::Utc>`] by default but if defined with
//! `scalar DateTimeUtc @juniper(with_time_zone: false)` it will become [`chrono::naive::NaiveDateTime`].
//!
//! Juniper doesn't support [`chrono::Date`](https://docs.rs/chrono/0.4.9/chrono/struct.Date.html)
//! so therefore this library cannot support that either. You can read about Juniper's supported
//! integrations [here](https://docs.rs/juniper/0.13.1/juniper/integrations/index.html).
//!
//! [`chrono::DateTime<chrono::offset::Utc>`]: https://docs.rs/chrono/0.4.9/chrono/struct.DateTime.html
//! [`chrono::naive::NaiveDateTime`]: https://docs.rs/chrono/0.4.9/chrono/naive/struct.NaiveDateTime.html
//!
//! ## Interfaces
//!
//! Juniper has several ways of representing GraphQL interfaces in Rust. They are listed
//! [here](https://graphql-rust.github.io/juniper/master/types/interfaces.html) along with their
//! advantages and disadvantages.
//!
//! For the generated code we use the "enum value" pattern because we found it to be the most flexible.
//!
//! Abbreviated example (find [complete example here](https://github.com/davidpdrsn/juniper-from-schema/blob/master/examples/interface.rs)):
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper::*;
//! # use juniper_from_schema::graphql_schema;
//! # fn main() {}
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # pub struct Article { id: ID, text: String }
//! # impl ArticleFields for Article {
//! # fn field_id(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&ID> { unimplemented!() }
//! # fn field_text(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&String> { unimplemented!() }
//! # }
//! # pub struct Tweet { id: ID, text: String }
//! # impl TweetFields for Tweet {
//! # fn field_id(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&ID> { unimplemented!() }
//! # fn field_text(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&String> { unimplemented!() }
//! # }
//! #
//! graphql_schema! {
//! schema {
//! query: Query
//! }
//!
//! type Query {
//! search(query: String!): [SearchResult!]! @juniper(ownership: "owned")
//! }
//!
//! interface SearchResult {
//! id: ID!
//! text: String!
//! }
//!
//! type Article implements SearchResult {
//! id: ID!
//! text: String!
//! }
//!
//! type Tweet implements SearchResult {
//! id: ID!
//! text: String!
//! }
//! }
//!
//! pub struct Query;
//!
//! impl QueryFields for Query {
//! fn field_search(
//! &self,
//! executor: &Executor<Context>,
//! trail: &QueryTrail<SearchResult, juniper_from_schema::Walked>,
//! query: String,
//! ) -> FieldResult<Vec<SearchResult>> {
//! let article: Article = Article { id: ID::new("1"), text: "Business".to_string() };
//! let tweet: Tweet = Tweet { id: ID::new("2"), text: "1 weird tip".to_string() };
//!
//! let posts = vec![
//! SearchResult::from(article),
//! SearchResult::from(tweet),
//! ];
//!
//! Ok(posts)
//! }
//! }
//! ```
//!
//! The enum that gets generated has variants for each type that implements the interface and also
//! implements `From<T>` for each type.
//!
//! ## Union types
//!
//! Union types are basically just interfaces so they work in very much the same way.
//!
//! Abbreviated example (find [complete example here](https://github.com/davidpdrsn/juniper-from-schema/blob/master/examples/union_types.rs)):
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper::*;
//! # use juniper_from_schema::graphql_schema;
//! # fn main() {}
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # pub struct Article { id: ID, text: String }
//! # impl ArticleFields for Article {
//! # fn field_id(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&ID> { unimplemented!() }
//! # fn field_text(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&String> { unimplemented!() }
//! # }
//! # pub struct Tweet { id: ID, text: String }
//! # impl TweetFields for Tweet {
//! # fn field_id(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&ID> { unimplemented!() }
//! # fn field_text(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&String> { unimplemented!() }
//! # }
//! #
//! graphql_schema! {
//! schema {
//! query: Query
//! }
//!
//! type Query {
//! search(query: String!): [SearchResult!]! @juniper(ownership: "owned")
//! }
//!
//! union SearchResult = Article | Tweet
//!
//! type Article {
//! id: ID!
//! text: String!
//! }
//!
//! type Tweet {
//! id: ID!
//! text: String!
//! }
//! }
//!
//! pub struct Query;
//!
//! impl QueryFields for Query {
//! fn field_search(
//! &self,
//! executor: &Executor<Context>,
//! trail: &QueryTrail<SearchResult, juniper_from_schema::Walked>,
//! query: String,
//! ) -> FieldResult<Vec<SearchResult>> {
//! let article: Article = Article { id: ID::new("1"), text: "Business".to_string() };
//! let tweet: Tweet = Tweet { id: ID::new("2"), text: "1 weird tip".to_string() };
//!
//! let posts = vec![
//! SearchResult::from(article),
//! SearchResult::from(tweet),
//! ];
//!
//! Ok(posts)
//! }
//! }
//! ```
//!
//! ## Input objects
//!
//! Input objects will be converted into Rust structs with public fields.
//!
//! Abbreviated example (find [complete example here](https://github.com/davidpdrsn/juniper-from-schema/blob/master/examples/input_types.rs)):
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper::*;
//! # use juniper_from_schema::graphql_schema;
//! # fn main() {}
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # pub struct Post { id: ID }
//! # impl PostFields for Post {
//! # fn field_id(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&ID> {
//! # unimplemented!()
//! # }
//! # fn field_title(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&String> {
//! # unimplemented!()
//! # }
//! # }
//! # pub struct Query;
//! # impl QueryFields for Query {
//! # fn field_noop(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&bool> {
//! # unimplemented!()
//! # }
//! # }
//! graphql_schema! {
//! schema {
//! query: Query
//! mutation: Mutation
//! }
//!
//! type Mutation {
//! createPost(input: CreatePost!): Post @juniper(ownership: "owned")
//! }
//!
//! input CreatePost {
//! title: String!
//! }
//!
//! type Post {
//! id: ID!
//! title: String!
//! }
//!
//! type Query { noop: Boolean! }
//! }
//!
//! pub struct Mutation;
//!
//! impl MutationFields for Mutation {
//! fn field_create_post(
//! &self,
//! executor: &Executor<Context>,
//! trail: &QueryTrail<Post, juniper_from_schema::Walked>,
//! input: CreatePost,
//! ) -> FieldResult<Option<Post>> {
//! let title: String = input.title;
//!
//! unimplemented!()
//! }
//! }
//! ```
//!
//! From that example `CreatePost` will be defined as
//!
//! ```
//! pub struct CreatePost {
//! pub title: String,
//! }
//! ```
//!
//! ## Enumeration types
//!
//! GraphQL enumeration types will be converted into normal Rust enums. The name of each variant
//! will be camel cased.
//!
//! Abbreviated example (find [complete example here](https://github.com/davidpdrsn/juniper-from-schema/blob/master/examples/enumeration_types.rs)):
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper::*;
//! # use juniper_from_schema::graphql_schema;
//! # fn main() {}
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # pub struct Post { id: ID }
//! # impl PostFields for Post {
//! # fn field_id(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&ID> {
//! # Ok(&self.id)
//! # }
//! # }
//! #
//! graphql_schema! {
//! schema {
//! query: Query
//! }
//!
//! enum Status {
//! PUBLISHED
//! UNPUBLISHED
//! }
//!
//! type Query {
//! allPosts(status: Status!): [Post!]! @juniper(ownership: "owned")
//! }
//!
//! type Post {
//! id: ID!
//! }
//! }
//!
//! pub struct Query;
//!
//! impl QueryFields for Query {
//! fn field_all_posts(
//! &self,
//! executor: &Executor<Context>,
//! trail: &QueryTrail<Post, juniper_from_schema::Walked>,
//! status: Status,
//! ) -> FieldResult<Vec<Post>> {
//! match status {
//! Status::Published => unimplemented!("find published posts"),
//! Status::Unpublished => unimplemented!("find unpublished posts"),
//! }
//! }
//! }
//! ```
//!
//! ## Default argument values
//!
//! In GraphQL you are able to provide default values for field arguments, provided the argument is
//! nullable.
//!
//! Arguments of the following types support default values:
//! - `Float`
//! - `Int`
//! - `String`
//! - `Boolean`
//! - Enumerations
//! - Input objects (as field arguments, see below)
//! - Lists containing some other supported type
//!
//! Abbreviated example (find [complete example here](https://github.com/davidpdrsn/juniper-from-schema/blob/master/examples/default_argument_values.rs)):
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper::*;
//! # use juniper_from_schema::graphql_schema;
//! # fn main() {}
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # pub struct Post { id: ID }
//! # impl PostFields for Post {
//! # fn field_id(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&ID> {
//! # Ok(&self.id)
//! # }
//! # }
//! #
//! graphql_schema! {
//! schema {
//! query: Query
//! }
//!
//! enum Status {
//! PUBLISHED
//! UNPUBLISHED
//! }
//!
//! input Pagination {
//! pageSize: Int!
//! cursor: ID
//! }
//!
//! type Query {
//! allPosts(
//! status: Status = PUBLISHED,
//! pagination: Pagination = { pageSize: 20 }
//! ): [Post!]! @juniper(ownership: "owned")
//! }
//!
//! type Post {
//! id: ID!
//! }
//! }
//!
//! pub struct Query;
//!
//! impl QueryFields for Query {
//! fn field_all_posts(
//! &self,
//! executor: &Executor<Context>,
//! trail: &QueryTrail<Post, juniper_from_schema::Walked>,
//! status: Status,
//! pagination: Pagination,
//! ) -> FieldResult<Vec<Post>> {
//! // `status` will be `Status::Published` if not given in the query
//!
//! match status {
//! Status::Published => unimplemented!("find published posts"),
//! Status::Unpublished => unimplemented!("find unpublished posts"),
//! }
//! }
//! }
//! ```
//!
//! ### Input object gotchas
//!
//! Defaults for input objects are only supported as field arguments. The following is not
//! supported
//!
//! ```graphql
//! input SomeType {
//! field: Int = 1
//! }
//! ```
//!
//! This isn't supported because [the spec is unclear about how to handle multiple nested
//! defaults](https://github.com/webonyx/graphql-php/issues/350).
//!
//! Also, defaults are only used if no arguments are passed. So given the schema
//!
//! ```graphql
//! input Input {
//! a: String
//! b: String
//! }
//!
//! type Query {
//! field(arg: Input = { a: "a" }): Int!
//! }
//! ```
//!
//! and the query
//!
//! ```graphql
//! query MyQuery {
//! field(arg: { b: "my b" })
//! }
//! ```
//!
//! The value of `arg` inside the resolver would be `Input { a: None, b: Some("my b") }`. Note that
//! even though `a` has a default value in the field doesn't get used here because we set `arg` in
//! the query.
//!
//! ## Subscriptions
//!
//! Subscriptions work differently from queries and mutations. Rather than completing a request by
//! sending just one result you instead receive a stream of results. The server can then publish
//! new results to the clients through the stream. The [juniper
//! book](https://graphql-rust.github.io/juniper/master/advanced/subscriptions.html) has more
//! details.
//!
//! The return type of your subscription resolvers must always return something that implements
//! [`futures::stream::Stream`]. By default that will be `Pin<Box<dyn Stream<Item = STREAM_ITEM_TYPE> + Send>>`.
//!
//! [`futures::stream::Stream`]: https://docs.rs/futures/0.3.6/futures/stream/trait.Stream.html
//!
//! Abbreviated example (find [complete example here](https://github.com/davidpdrsn/juniper-from-schema/blob/master/examples/subscription.rs)):
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper::*;
//! # use juniper_from_schema::graphql_schema;
//! # fn main() {}
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # pub struct Query;
//! # impl QueryFields for Query {
//! # fn field_ping(&self, executor: &Executor<Context>) -> FieldResult<&bool> {
//! # todo!()
//! # }
//! # }
//! use futures::stream::Stream;
//! use std::pin::Pin;
//!
//! graphql_schema! {
//! schema {
//! query: Query
//! subscription: Subscription
//! }
//!
//! type Query {
//! // Query must have at least one field
//! ping: Boolean!
//! }
//!
//! type Subscription {
//! idsOfNewThings: ID! @juniper(ownership: "owned", infallible: true)
//! }
//! }
//!
//! pub struct Subscription;
//!
//! impl SubscriptionFields for Subscription {
//! fn field_ids_of_new_things(
//! &self,
//! executor: &Executor<Context>,
//! ) -> Pin<Box<dyn Stream<Item = ID> + Send>> {
//! // `futures::stream::iter` creates a stream out of any iterator
//! // this is useful for demonstration
//! Box::pin(futures::stream::iter(vec![
//! ID::new("1"),
//! ID::new("2"),
//! ID::new("3"),
//! ]))
//! }
//! }
//! ```
//!
//! ### Customizing the stream type
//!
//! Using `Pin<Box<dyn Stream<Item = ID> + Send>>` as your stream type is nice for most use
//! cases. However if you want to save the allocation and have a concrete stream type you can
//! change the type with `@juniper(stream_type: "IdStream")`.
//!
//! Abbreviated example:
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper::*;
//! # use juniper_from_schema::graphql_schema;
//! # fn main() {}
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # pub struct Query;
//! # impl QueryFields for Query {
//! # fn field_ping(&self, executor: &Executor<Context>) -> FieldResult<&bool> {
//! # todo!()
//! # }
//! # }
//! use futures::stream::Stream;
//!
//! graphql_schema! {
//! schema {
//! query: Query
//! subscription: Subscription
//! }
//!
//! type Query {
//! // Query must have at least one field
//! ping: Boolean!
//! }
//!
//! type Subscription {
//! idsOfNewThings: ID! @juniper(stream_type: "IdStream", infallible: true, ownership: "owned")
//! }
//! }
//!
//! pub struct Subscription;
//!
//! impl SubscriptionFields for Subscription {
//! fn field_ids_of_new_things(
//! &self,
//! executor: &Executor<Context>,
//! ) -> IdStream {
//! IdStream
//! }
//! }
//!
//! pub struct IdStream;
//!
//! impl Stream for IdStream {
//! type Item = ID;
//!
//! fn poll_next(
//! self: std::pin::Pin<&mut Self>,
//! cx: &mut futures::task::Context<'_>,
//! ) -> futures::task::Poll<Option<Self::Item>> {
//! // your implementation here
//! # todo!()
//! }
//! }
//! ```
//!
//! ### Interactions with `@juniper` directives
//!
//! There are a few things to keep in mind that are specific to subscriptions and the `@juniper`
//! directive.
//!
//! Consider you have a field with `@juniper(infallible: false)`. Does that mean the resolver that
//! produces the stream can fail or does it mean that the stream itself produces `Result`s?
//!
//! In juniper-from-schema we've chosen at `infallible`, `ownership`, and `async` applies to the
//! resolver that produces the stream. This is to remain consistent with the rest of the library.
//!
//! If you actually want a stream of `Result`s you can use the `@juniper(stream_item_infallible:
//! false)` directive.
//!
//! By default `stream_item_infallible` is `true` meaning your stream doesn't produce `Result`s but
//! instead successful values.
//!
//! Abbreviated example:
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper::*;
//! # use juniper_from_schema::graphql_schema;
//! # fn main() {}
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # pub struct Query;
//! # impl QueryFields for Query {
//! # fn field_ping(&self, executor: &Executor<Context>) -> FieldResult<&bool> {
//! # todo!()
//! # }
//! # }
//! use futures::stream::Stream;
//!
//! graphql_schema! {
//! schema {
//! query: Query
//! subscription: Subscription
//! }
//!
//! type Query {
//! // Query must have at least one field
//! ping: Boolean!
//! }
//!
//! type Subscription {
//! idsOfNewThings: ID! @juniper(
//! // stream is fallible, so it produces `Result`s
//! stream_item_infallible: false,
//! // type of our stream
//! stream_type: "IdStream",
//! // creating the stream itself can fail
//! infallible: false,
//! // the stream we produce is owned
//! ownership: "owned"
//! )
//! }
//! }
//!
//! pub struct Subscription;
//!
//! impl SubscriptionFields for Subscription {
//! fn field_ids_of_new_things(
//! &self,
//! executor: &Executor<Context>,
//! ) -> FieldResult<IdStream> {
//! Ok(IdStream)
//! }
//! }
//!
//! pub struct IdStream;
//!
//! impl Stream for IdStream {
//! type Item = FieldResult<ID>;
//!
//! fn poll_next(
//! self: std::pin::Pin<&mut Self>,
//! cx: &mut futures::task::Context<'_>,
//! ) -> futures::task::Poll<Option<Self::Item>> {
//! // your implementation here
//! # todo!()
//! }
//! }
//! ```
//!
//! Something like `@juniper(stream_item_ownership: "borrowed")` is not supported and all streams
//! must therefore produce owned values.
//!
//! Your stream resolvers are also required to use `@juniper(ownership: "owned")`. `"as_ref"` or
//! `"borrowed"` are not supported:
//!
//! ```compile_fail
//! # #[macro_use]
//! # extern crate juniper;
//! # use std::pin::Pin;
//! # use juniper::*;
//! # use juniper::futures::stream::Stream;
//! # use juniper_from_schema::graphql_schema;
//! # fn main() {}
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # pub struct Query;
//! # impl QueryFields for Query {
//! # fn field_ping(&self, executor: &Executor<Context>) -> FieldResult<&bool> {
//! # todo!()
//! # }
//! # }
//! use futures::stream::Stream;
//!
//! graphql_schema! {
//! schema {
//! query: Query
//! subscription: Subscription
//! }
//!
//! type Query {
//! // Query must have at least one field
//! ping: Boolean!
//! }
//!
//! type Subscription {
//! // "as_ref" is not supported
//! asRefNotSupported: [ID!]! @juniper(infallible: true, ownership: "as_ref")
//!
//! // neither is "borrowed"
//! borrowedNotSupported: ID! @juniper(infallible: true, ownership: "borrowed")
//! }
//! }
//!
//! pub struct Subscription;
//!
//! impl SubscriptionFields for Subscription {
//! fn field_as_ref_not_supported(
//! &self,
//! executor: &Executor<Context>,
//! ) -> Pin<Box<dyn Stream<Item = Vec<&ID>> + Send>> {
//! // ...
//! # todo!()
//! }
//!
//! fn field_borrowed_not_supported(
//! &self,
//! executor: &Executor<Context>,
//! ) -> Pin<Box<dyn Stream<Item = &ID> + Send>> {
//! // ...
//! # todo!()
//! }
//! }
//! ```
//!
//! # Supported schema directives
//!
//! A number of [schema directives][] are supported that lets you customize the generated code:
//!
//! - `@juniper(ownership: "owned|borrowed|as_ref")`. For customizing ownership of returned data.
//! More info [here](#customizing-ownership).
//! - `@juniper(infallible: true|false)`. Customize if a field should return `Result<T, _>` or
//! just `T`. More info
//! [here](http://localhost:4000/juniper_from_schema/index.html#infallible-fields).
//! - `@juniper(async: true|false)`. For choosing whether your resolver function should be sync or
//! async. The default is sync. More info [here](#async-resolvers).
//! - `@juniper(stream_item_infallible: true|false)`. For choosing whether the stream produces
//! `Result`s or plain values. Default is `true` meaning the stream does not produce `Result`s.
//! - `@deprecated`. For deprecating types in your schema. Also supports supplying a reason with
//! `@deprecated(reason: "...")`
//!
//! [schema directives]: https://www.apollographql.com/docs/apollo-server/schema/directives/
//!
//! ## Definition for `@juniper`
//!
//! Some tools that operate on your GraphQL schema require you to include the definition for all
//! directives used. So in case you need it the definition for `@juniper` is:
//!
//! ```graphql
//! directive @juniper(
//! ownership: String = "borrowed",
//! infallible: Boolean = false,
//! with_time_zone: Boolean = true,
//! async: Boolean = false,
//! stream_item_infallible: Boolean = true,
//! stream_type: String = null
//! ) on FIELD_DEFINITION | SCALAR
//! ```
//!
//! This directive definition is allowed in your schema, as well as any other directive definition.
//! Definitions of `@juniper` that differ from this are not allowed though.
//!
//! The definition might change in future versions. Please refer to the [changelog][].
//!
//! juniper-from-schema doesn't require to put this in your schema, so you only need to include it
//! if some other tool requires it.
//!
//! [changelog]: https://github.com/davidpdrsn/juniper-from-schema/blob/master/CHANGELOG.md
//!
//! ## Customizing ownership
//!
//! By default all fields return borrowed values. Specifically the type is
//! `juniper::FieldResult<&'a T>` where `'a` is the lifetime of `self`. This works well for
//! returning data owned by `self` and avoids needless `.clone()` calls you would need if fields
//! returned owned values.
//!
//! However if you need to change the ownership you have to add the directive
//! `@juniper(ownership:)` to the field in the schema.
//!
//! It takes the following arguments:
//!
//! - `@juniper(ownership: "borrowed")`: The data returned will be borrowed from `self`
//! (`FieldResult<&T>`).
//! - `@juniper(ownership: "owned")`: The return type will be owned (`FieldResult<T>`).
//! - `@juniper(ownership: "as_ref")`: Only applicable for `Option` and `Vec` return types. Changes
//! the inner type to be borrowed (`FieldResult<Option<&T>>` or `FieldResult<Vec<&T>>`).
//!
//! Note that fields in subscription types must use `@juniper(ownership: "owned")`. `"as_ref"` or
//! `"borrowed"` are not supported.
//!
//! Example:
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper_from_schema::*;
//! # use juniper::*;
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # fn main() {}
//! graphql_schema! {
//! schema {
//! query: Query
//! }
//!
//! type Query {
//! borrowed: String!
//! owned: String! @juniper(ownership: "owned")
//! asRef: String @juniper(ownership: "as_ref")
//! }
//! }
//!
//! pub struct Query;
//!
//! impl QueryFields for Query {
//! fn field_borrowed(&self, _: &Executor<Context>) -> FieldResult<&String> {
//! // ...
//! # unimplemented!()
//! }
//!
//! fn field_owned(&self, _: &Executor<Context>) -> FieldResult<String> {
//! // ...
//! # unimplemented!()
//! }
//!
//! fn field_as_ref(&self, _: &Executor<Context>) -> FieldResult<Option<&String>> {
//! // ...
//! # unimplemented!()
//! }
//! }
//! ```
//!
//! All field arguments will be owned.
//!
//! ## Infallible fields
//!
//! By default the generated resolvers are fallible, meaining they return a `Result<T, _>` rather
//! than a bare `T`. You can customize that using `@juniper(infallible: true)`.
//!
//! Example:
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper_from_schema::*;
//! # use juniper::*;
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # fn main() {}
//! graphql_schema! {
//! schema {
//! query: Query
//! }
//!
//! type Query {
//! canError: String!
//! cannotError: String! @juniper(infallible: true)
//! cannotErrorAndOwned: String! @juniper(infallible: true, ownership: "owned")
//! }
//! }
//!
//! pub struct Query;
//!
//! impl QueryFields for Query {
//! fn field_can_error(&self, _: &Executor<Context>) -> FieldResult<&String> {
//! // ...
//! # unimplemented!()
//! }
//!
//! fn field_cannot_error(&self, _: &Executor<Context>) -> &String {
//! // ...
//! # unimplemented!()
//! }
//!
//! fn field_cannot_error_and_owned(&self, _: &Executor<Context>) -> String {
//! // ...
//! # unimplemented!()
//! }
//! }
//! ```
//!
//! ## Async resolvers
//!
//! By default the generated resolvers are synchronous. If you want an async resolver instead you
//! can change it with `@juniper(async: true)`.
//!
//! Example:
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper_from_schema::*;
//! # use juniper::*;
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # fn main() {}
//! // `async` methods are currently not supported in traits. So we use "async_trait" to make them
//! // work. "async_trait" is also used by juniper under the covers.
//! use async_trait::async_trait;
//!
//! graphql_schema! {
//! schema {
//! query: Query
//! }
//!
//! type Query {
//! findUser(id: ID!): User! @juniper(async: true, ownership: "owned")
//!
//! // async resolvers also support `ownership: "as_ref"`
//! allUsers: [User!]! @juniper(async: true, ownership: "as_ref")
//! }
//!
//! type User {
//! id: ID! @juniper(infallible: true)
//! }
//! }
//!
//! pub struct Query;
//!
//! #[async_trait]
//! impl QueryFields for Query {
//! // Async resolvers are required to specify the lifetimes 's, 'r, and 'a because of how
//! // "async_trait" works
//! async fn field_find_user<'s, 'r, 'a>(
//! &'s self,
//! _: &Executor<'r, 'a, Context>,
//! _: &QueryTrail<'r, User, Walked>,
//! id: ID,
//! ) -> FieldResult<User> {
//! // ...
//! # unimplemented!()
//! }
//!
//! // Use `'s` to return data borrowed from `self`
//! async fn field_all_users<'s, 'r, 'a>(
//! &'s self,
//! _: &Executor<'r, 'a, Context>,
//! _: &QueryTrail<'r, User, Walked>,
//! ) -> FieldResult<Vec<&'s User>> {
//! // ...
//! # unimplemented!()
//! }
//! }
//!
//! pub struct User {
//! id: ID,
//! }
//!
//! impl UserFields for User {
//! fn field_id(&self, _: &Executor<Context>) -> &ID {
//! &self.id
//! }
//! }
//! ```
//!
//! # GraphQL to Rust types
//!
//! This is how the standard GraphQL types will be mapped to Rust:
//!
//! - `Int` -> `i32`
//! - `Float` -> `f64`
//! - `String` -> `String`
//! - `Boolean` -> `bool`
//! - `ID` -> [`juniper::ID`](https://docs.rs/juniper/latest/juniper/struct.ID.html)
//!
//! # Query trails
//!
//! If you're not careful about preloading associations for deeply nested queries you risk getting
//! lots of [N+1 query bugs][]. Juniper provides a [look ahead API][] which lets you inspect things
//! coming up further down a query. However the API is string based, so you risk making typos and
//! checking for fields that don't exist.
//!
//! `QueryTrail` is a thin wrapper around Juniper look aheads with generated methods for each field
//! on all your types. This means the compiler will reject your code if you're checking for invalid
//! fields.
//!
//! Resolver methods (`field_*`) that return object types (non scalar values) will also get a
//! `QueryTrail` argument besides the executor.
//!
//! Since the `QueryTrail` type itself is defined in this crate (rather than being inserted into
//! your code) we cannot directly add methods for your GraphQL fields. Those methods have to be
//! added through ["extension traits"](http://xion.io/post/code/rust-extension-traits.html). So if
//! you see an error like
//!
//! ```text
//! | trail.foo();
//! | ^^^ method not found in `&juniper_from_schema::QueryTrail<'r, User, juniper_from_schema::Walked>`
//! |
//! = help: items from traits can only be used if the trait is in scope
//! help: the following trait is implemented but not in scope, perhaps add a `use` for it:
//! |
//! 2 | use crate::graphql_schema::query_trails::QueryTrailUserExtensions;
//! |
//! ```
//!
//! Then adding `use crate::graphql_schema::query_trails::*` to you module should fix it. This is
//! necessary because all the extention traits are generated inside a module called `query_trails`.
//! This is done so you can glob import the `QueryTrail` extension traits without glob importing
//! everything from your GraphQL schema.
//!
//! If you just want everything from the schema `use crate::graphql_schema::*` will also bring in
//! the extension traits.
//!
//! [N+1 query bugs]: https://secure.phabricator.com/book/phabcontrib/article/n_plus_one/
//! [look ahead API]: https://docs.rs/juniper/0.11.1/juniper/struct.LookAheadSelection.html
//!
//! ## Abbreviated example
//!
//! Find [complete example here](https://github.com/davidpdrsn/juniper-from-schema/blob/master/examples/query_trails.rs)
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper::*;
//! # use juniper_from_schema::graphql_schema;
//! # fn main() {}
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! #
//! graphql_schema! {
//! schema {
//! query: Query
//! }
//!
//! type Query {
//! allPosts: [Post!]! @juniper(ownership: "owned")
//! }
//!
//! type Post {
//! id: Int!
//! author: User!
//! }
//!
//! type User {
//! id: Int!
//! }
//! }
//!
//! pub struct Query;
//!
//! impl QueryFields for Query {
//! fn field_all_posts(
//! &self,
//! executor: &Executor<Context>,
//! trail: &QueryTrail<Post, juniper_from_schema::Walked>,
//! ) -> FieldResult<Vec<Post>> {
//! // Check if the query includes the author
//! if let Some(_) = trail.author().walk() {
//! // Somehow preload the users to avoid N+1 query bugs
//! // Exactly how to do this depends on your setup
//! }
//!
//! // Normally this would come from the database
//! let post = Post {
//! id: 1,
//! author: User { id: 1 },
//! };
//!
//! Ok(vec![post])
//! }
//! }
//!
//! pub struct Post {
//! id: i32,
//! author: User,
//! }
//!
//! impl PostFields for Post {
//! fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
//! Ok(&self.id)
//! }
//!
//! fn field_author(
//! &self,
//! executor: &Executor<Context>,
//! trail: &QueryTrail<User, juniper_from_schema::Walked>,
//! ) -> FieldResult<&User> {
//! Ok(&self.author)
//! }
//! }
//!
//! pub struct User {
//! id: i32,
//! }
//!
//! impl UserFields for User {
//! fn field_id(
//! &self,
//! executor: &Executor<Context>,
//! ) -> FieldResult<&i32> {
//! Ok(&self.id)
//! }
//! }
//! ```
//!
//! ## Types
//!
//! A query trail has two generic parameters: `QueryTrail<'r, T, K>`. `T` is the type the current
//! field returns and `K` is either `Walked` or `NotWalked`.
//!
//! The lifetime `'r` comes from Juniper and is the lifetime of the incoming query.
//!
//! ### `T`
//!
//! The `T` allows us to implement different methods for different types. For example in the
//! example above we implement `id` and `author` for `QueryTrail<'r, Post, K>` but only `id` for
//! `QueryTrail<'r, User, K>`.
//!
//! If your field returns a `Vec<T>` or `Option<T>` the given query trail will be `QueryTrail<'r,
//! T, _>`. So `Vec` or `Option` will be removed and you'll only be given the inner most type.
//! That is because in the GraphQL query syntax it doesn't matter if you're querying a `User`
//! or `[User]`. The fields you have access to are the same.
//!
//! ### `K`
//!
//! The `Walked` and `NotWalked` types are used to check if a given trail has been checked to
//! actually be part of a query. Calling any method on a `QueryTrail<'r, T, K>` will return
//! `QueryTrail<'r, T, NotWalked>`, and to check if the trail is actually part of the query you have
//! to call `.walk()` which returns `Option<QueryTrail<'r, T, Walked>>`. If that is a `Some(_)`
//! you'll know the trail is part of the query and you can do whatever preloading is necessary.
//!
//! Example:
//!
//! ```ignore
//! if let Some(walked_trail) = trail
//! .some_field()
//! .some_other_field()
//! .third_field()
//! .walk()
//! {
//! // preload stuff
//! }
//! ```
//!
//! You can always run `cargo doc` and inspect all the methods on `QueryTrail` and in which
//! contexts you can call them.
//!
//! ## Downcasting for interface and union `QueryTrail`s
//!
//! _This section is mostly relevant if you're using
//! [juniper-eager-loading](https://crates.io/crates/juniper-eager-loading) however it isn't
//! specific to that library._
//!
//! If you have a `QueryTrail<'r, T, Walked>` where `T` is an interface or union type you can use
//! `.downcast()` to convert that `QueryTrail` into one of the implementors of the interface or
//! union.
//!
//! Example:
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper::*;
//! # use juniper_from_schema::graphql_schema;
//! # fn main() {}
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # pub struct Article { id: ID }
//! # impl ArticleFields for Article {
//! # fn field_id(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&ID> { unimplemented!() }
//! # }
//! # pub struct Tweet { id: ID, text: String }
//! # impl TweetFields for Tweet {
//! # fn field_id(
//! # &self,
//! # executor: &Executor<Context>,
//! # ) -> FieldResult<&ID> { unimplemented!() }
//! # }
//! #
//! graphql_schema! {
//! schema {
//! query: Query
//! }
//!
//! type Query {
//! search(query: String!): [SearchResult!]!
//! }
//!
//! interface SearchResult {
//! id: ID!
//! }
//!
//! type Article implements SearchResult {
//! id: ID!
//! }
//!
//! type Tweet implements SearchResult {
//! id: ID!
//! }
//! }
//!
//! pub struct Query;
//!
//! impl QueryFields for Query {
//! fn field_search(
//! &self,
//! executor: &Executor<Context>,
//! trail: &QueryTrail<SearchResult, juniper_from_schema::Walked>,
//! query: String,
//! ) -> FieldResult<&Vec<SearchResult>> {
//! let article_trail: QueryTrail<Article, Walked> = trail.downcast();
//! let tweet_trail: QueryTrail<Tweet, Walked> = trail.downcast();
//!
//! // ...
//! # unimplemented!()
//! }
//! }
//! ```
//!
//! ### Why is this useful?
//!
//! If you were do perform some kind of preloading of data you might have a function that inspects
//! a `QueryTrail` and loads the necessary data from a database. Such a function could look like
//! this:
//!
//! ```ignore
//! fn preload_users(
//! mut users: Vec<User>,
//! query_trail: &QueryTrail<User, Walked>,
//! db: &Database,
//! ) -> Vec<User> {
//! // ...
//! }
//! ```
//!
//! This function works well when we have field that returns `[User!]!`. That field is going to get
//! a `QueryTrail<'r, User, Walked>` which is exactly what `preload_users` needs.
//!
//! However, now imagine you have a schema like this:
//!
//! ```graphql
//! type Query {
//! search(query: String!): [SearchResult!]!
//! }
//!
//! union SearchResult = User | City | Country
//!
//! type User {
//! id: ID!
//! city: City!
//! }
//!
//! type City {
//! id: ID!
//! country: Country!
//! }
//!
//! type Country {
//! id: ID!
//! }
//! ```
//!
//! The method `QueryFields::field_search` will receive a `QueryTrail<'r, SearchResult, Walked>`.
//! That type doesn't work with `preload_users`. So we have to convert our `QueryTrail<'r,
//! SearchResult, Walked>` into `QueryTrail<'r, User, Walked>`.
//!
//! This can be done by calling `.downcast()` which automatically gets implemented for interface and
//! union query trails. See above for an example.
//!
//! ## `QueryTrail`s for fields that take arguments
//!
//! Sometimes you have GraphQL fields that take arguments that impact which things your resolvers
//! should return. `QueryTrail` therefore also allows you inspect arguments to fields.
//!
//! Abbreviated example:
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper_from_schema::*;
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # fn main() {}
//! # pub struct Country {}
//! # impl CountryFields for Country {
//! # fn field_users<'r, 'a>(
//! # &self,
//! # executor: &juniper::Executor<'r, 'a, Context>,
//! # trail: &QueryTrail<'r, User, Walked>,
//! # active_since: DateTime<Utc>,
//! # ) -> juniper::FieldResult<Vec<User>> {
//! # unimplemented!()
//! # }
//! # }
//! # pub struct User {}
//! # impl UserFields for User {
//! # fn field_id<'r, 'a>(
//! # &self,
//! # executor: &juniper::Executor<'r, 'a, Context>,
//! # ) -> juniper::FieldResult<&juniper::ID> {
//! # unimplemented!()
//! # }
//! # }
//! use chrono::prelude::*;
//!
//! graphql_schema! {
//! schema {
//! query: Query
//! }
//!
//! type Query {
//! countries: [Country!]! @juniper(ownership: "owned")
//! }
//!
//! type Country {
//! users(activeSince: DateTimeUtc!): [User!]! @juniper(ownership: "owned")
//! }
//!
//! type User {
//! id: ID!
//! }
//!
//! scalar DateTimeUtc
//! }
//!
//! pub struct Query;
//!
//! impl QueryFields for Query {
//! fn field_countries<'r, 'a>(
//! &self,
//! executor: &'a juniper::Executor<'r, 'a, Context>,
//! trail: &'a QueryTrail<'r, Country, Walked>
//! ) -> juniper::FieldResult<Vec<Country>> {
//! // Get struct that has all arguments passed to `Country.users`
//! let args: CountryUsersArgs<'a> = trail.users_args();
//!
//! // The struct has methods for each argument, e.g. `active_since`.
//! //
//! // Notice that it automatically converts the incoming value to
//! // a `DateTime<Utc>`.
//! let _: DateTime<Utc> = args.active_since();
//!
//! # unimplemented!()
//! // ...
//! }
//! }
//! ```
//!
//! You can also elide the `'a` lifetime:
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper_from_schema::*;
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # fn main() {}
//! # pub struct Country {}
//! # impl CountryFields for Country {
//! # fn field_users(
//! # &self,
//! # executor: &juniper::Executor<Context>,
//! # trail: &QueryTrail<User, Walked>,
//! # active_since: DateTime<Utc>,
//! # ) -> juniper::FieldResult<Vec<User>> {
//! # unimplemented!()
//! # }
//! # }
//! # pub struct User {}
//! # impl UserFields for User {
//! # fn field_id(
//! # &self,
//! # executor: &juniper::Executor<Context>,
//! # ) -> juniper::FieldResult<&juniper::ID> {
//! # unimplemented!()
//! # }
//! # }
//! # use chrono::prelude::*;
//! # graphql_schema! {
//! # schema {
//! # query: Query
//! # }
//! # type Query {
//! # countries: [Country!]! @juniper(ownership: "owned")
//! # }
//! # type Country {
//! # users(activeSince: DateTimeUtc!): [User!]! @juniper(ownership: "owned")
//! # }
//! # type User {
//! # id: ID!
//! # }
//! # scalar DateTimeUtc
//! # }
//! # pub struct Query;
//! #
//! impl QueryFields for Query {
//! fn field_countries(
//! &self,
//! executor: &juniper::Executor<Context>,
//! trail: &QueryTrail<Country, Walked>
//! ) -> juniper::FieldResult<Vec<Country>> {
//! let args: CountryUsersArgs = trail.users_args();
//!
//! # unimplemented!()
//! // ...
//! }
//! }
//! ```
//!
//! The name of the arguments struct will always be `{name of type}{name of field}Args` (e.g.
//! `CountryUsersArgs`). The method names will always be the name of the arguments in snake case.
//!
//! The `*_args` method is only defined on `Walked` query trails so if you get an error like:
//!
//! ```text
//! ---- src/lib.rs - (line 10) stdout ----
//! error[E0599]: no method named `users_args` found for type `&QueryTrail<'r, Country, Walked>` in the current
//! scope
//! --> src/lib.rs:10:1
//! |
//! 10 | trail.users_args();
//! | ^^^^^^^^^^^^ method not found in `&QueryTrail<'r, Country, Walked>`
//! ```
//!
//! It is likely because you've forgotten to call [`.walk()`][] on `trail`.
//!
//! [`.walk()`]: struct.QueryTrail.html#method.walk
//!
//! Remember that you can always run `cargo doc` to get a high level overview of the generated
//! code.
//!
//! # Customizing the error type
//!
//! By default the return type of the generated field methods will be [`juniper::FieldResult<T>`].
//! That is just a type alias for `std::result::Result<T, juniper::FieldError>`. Should you want to
//! use a different error type than [`juniper::FieldError`] that can be done by passing `,
//! error_type: YourType` to [`graphql_schema_from_file!`].
//!
//! Just keep in that your custom error type must implement [`juniper::IntoFieldError`] to
//! type check.
//!
//! Example:
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper::*;
//! # use juniper_from_schema::graphql_schema_from_file;
//! # fn main() {}
//! # pub struct Context;
//! # impl juniper::Context for Context {}
//! # pub struct Mutation;
//! # impl MutationFields for Mutation {
//! # fn field_noop(&self, executor: &Executor<Context>) -> Result<&bool, MyError> {
//! # Ok(&true)
//! # }
//! # }
//! graphql_schema_from_file!("tests/schemas/doc_schema.graphql", error_type: MyError);
//!
//! pub struct MyError(String);
//!
//! impl juniper::IntoFieldError for MyError {
//! fn into_field_error(self) -> juniper::FieldError {
//! // Perform custom error handling
//! juniper::FieldError::from(self.0)
//! }
//! }
//!
//! pub struct Query;
//!
//! impl QueryFields for Query {
//! fn field_hello_world(
//! &self,
//! executor: &Executor<Context>,
//! name: String,
//! ) -> Result<String, MyError> {
//! Ok(format!("Hello, {}!", name))
//! }
//! }
//! ```
//!
//! [`graphql_schema!`] does not support changing the error type.
//!
//! [`graphql_schema!`]: macro.graphql_schema.html
//! [`graphql_schema_from_file!`]: macro.graphql_schema_from_file.html
//! [`juniper::IntoFieldError`]: https://docs.rs/juniper/0.11.1/juniper/trait.IntoFieldError.html
//! [`juniper::FieldError`]: https://docs.rs/juniper/0.11.1/juniper/struct.FieldError.html
//! [`juniper::FieldResult<T>`]: https://docs.rs/juniper/0.11.1/juniper/type.FieldResult.html
//!
//! # Customizing the context type
//!
//! By default the generate code will assume your context type is called `Context`. If that is not
//! the case you can customize it by calling [`graphql_schema_from_file!`] with `context_type: NewName`.
//!
//! Example:
//!
//! ```
//! # #[macro_use]
//! # extern crate juniper;
//! # use juniper::*;
//! # use juniper_from_schema::graphql_schema_from_file;
//! # fn main() {}
//! # pub struct Mutation;
//! # impl MutationFields for Mutation {
//! # fn field_noop(&self, executor: &Executor<MyContext>) -> juniper::FieldResult<&bool> {
//! # Ok(&true)
//! # }
//! # }
//! graphql_schema_from_file!("tests/schemas/doc_schema.graphql", context_type: MyContext);
//!
//! pub struct MyContext;
//! impl juniper::Context for MyContext {}
//!
//! pub struct Query;
//!
//! impl QueryFields for Query {
//! fn field_hello_world(
//! &self,
//! executor: &Executor<MyContext>,
//! name: String,
//! ) -> juniper::FieldResult<String> {
//! Ok(format!("Hello, {}!", name))
//! }
//! }
//! ```
//!
//! [`graphql_schema!`] does not support changing the context type.
//!
//! [`graphql_schema!`]: macro.graphql_schema.html
//! [`graphql_schema_from_file!`]: macro.graphql_schema_from_file.html
//!
//! # Inspecting the generated code
//!
//! If you wish to see exactly what code gets generated you can set the env var
//! `JUNIPER_FROM_SCHEMA_DEBUG` to `1` when compiling. For example:
//!
//! ```bash
//! JUNIPER_FROM_SCHEMA_DEBUG=1 cargo build
//! ```
//!
//! The code will not be formatted so it might be tricky to read. The easiest way to fix this is to
//! copy the printed code to a file and run it through [rustfmt].
//!
//! [rustfmt]: https://github.com/rust-lang/rustfmt
//!
//! # Generating code in "build.rs"
//!
//! If generating the code from a procedural macro isn't your thing you can also generate the code
//! from a "build.rs" file. Add [juniper-from-schema-build] as a build dependency and call the
//! appropriate function. See its docs for examples and more info.
//!
//! [juniper-from-schema-build]: https://crates.io/crates/juniper-from-schema-build
#![deny(
missing_docs,
unused_imports,
dead_code,
unused_variables,
unused_must_use
)]
#![doc(html_root_url = "https://docs.rs/juniper-from-schema/0.5.2")]
use juniper::{DefaultScalarValue, LookAheadSelection};
use std::marker::PhantomData;
// re-export juniper here so we're sure to use the same version everywhere
#[doc(hidden)]
pub use futures;
#[doc(hidden)]
pub use juniper;
pub use juniper_from_schema_proc_macro::{graphql_schema, graphql_schema_from_file};
/// A type used to parameterize `QueryTrail` to know that `walk` has been called.
pub struct Walked;
/// A type used to parameterize `QueryTrail` to know that `walk` has *not* been called.
pub struct NotWalked;
/// A wrapper around a `juniper::LookAheadSelection` with methods for each possible child.
pub struct QueryTrail<'r, T, K> {
// These fields are required by the macros but you shouldn't rely them. They might change
// without a major version increase.
#[doc(hidden)]
pub look_ahead: Option<&'r LookAheadSelection<'r, DefaultScalarValue>>,
#[doc(hidden)]
pub node_type: PhantomData<T>,
#[doc(hidden)]
pub walked: K,
}
impl<'r, T> QueryTrail<'r, T, NotWalked> {
/// Check if the trail is present in the query being executed
pub fn walk(self) -> Option<QueryTrail<'r, T, Walked>> {
match self.look_ahead {
Some(inner) => Some(QueryTrail {
look_ahead: Some(inner),
node_type: self.node_type,
walked: Walked,
}),
None => None,
}
}
}
impl<'r, T, K> QueryTrail<'r, T, K> {
#[allow(clippy::new_ret_no_self)]
#[doc(hidden)]
#[allow(missing_docs)]
// This method is required by the macros but you shouldn't rely them. They might change
// without a major version increase.
pub fn new(lh: &'r LookAheadSelection<'r, DefaultScalarValue>) -> QueryTrail<'r, T, Walked> {
QueryTrail {
look_ahead: Some(lh),
node_type: PhantomData,
walked: Walked,
}
}
}
/// Include the code generated by "juniper-from-schema-build" in a "build.rs" file.
///
/// Example:
///
/// ```rust,ignore
/// juniper_from_schema::include_schema!();
/// ```
#[macro_export]
macro_rules! include_schema {
() => {
std::include!(std::concat!(
std::env!("OUT_DIR"),
"/juniper_from_schema_graphql_schema.rs"
));
};
}
#[cfg(test)]
mod test {
#[allow(unused_imports)]
use super::*;
use trybuild::TestCases;
#[test]
fn test_compile_pass() {
let t = TestCases::new();
setup_subscription_tests("pass", &t);
setup_subscription_tests("fail", &t);
t.pass("tests/compile_pass/*.rs");
t.compile_fail("tests/compile_fail/*.rs");
}
#[allow(dead_code)]
fn setup_subscription_tests(outcome: &str, t: &TestCases) {
for entry in std::fs::read_dir(format!("tests/subscriptions/{}", outcome)).unwrap() {
let path = entry.unwrap().path();
let file_name = path.file_name().unwrap().to_str().unwrap();
if !file_name.contains(".rs") {
continue;
}
match outcome {
"pass" => t.pass(&format!("tests/subscriptions/{}/{}", outcome, file_name)),
"fail" => t.compile_fail(&format!("tests/subscriptions/{}/{}", outcome, file_name)),
other => panic!("Unsupported outcome {:?}", other),
}
}
}
}
================================================
FILE: juniper-from-schema/tests/compile_fail/docs_on_special_case_scalars.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
use url::Url;
juniper_from_schema::graphql_schema! {
schema {
query: Query
}
type Query {
foo: String! @juniper(ownership: "owned")
}
"Url docs"
scalar Url
"DateTimeUtc docs"
scalar DateTimeUtc
"Date docs"
scalar Date
"Uuid docs"
scalar Uuid
}
pub struct Query;
impl QueryFields for Query {
fn field_foo(&self, _: &Executor<Context>) -> FieldResult<String> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_fail/docs_on_special_case_scalars.stderr
================================================
error: proc macro panicked
--> $DIR/docs_on_special_case_scalars.rs:6:1
|
6 | / juniper_from_schema::graphql_schema! {
7 | | schema {
8 | | query: Query
9 | | }
... |
25 | | scalar Uuid
26 | | }
| |_^
|
= help: message:
error: Special case scalars don't support having descriptions because the Rust types are defined in external crates
--> schema:2:62
|
2 | { foo : String ! @ juniper(ownership : "owned") } "Url docs" scalar Url
| ^
error: Special case scalars don't support having descriptions because the Rust types are defined in external crates
--> schema:3:20
|
3 | "DateTimeUtc docs" scalar DateTimeUtc "Date docs" scalar Date "Uuid docs"
| ^
error: Special case scalars don't support having descriptions because the Rust types are defined in external crates
--> schema:3:51
|
3 | "DateTimeUtc docs" scalar DateTimeUtc "Date docs" scalar Date "Uuid docs"
| ^
error: Special case scalars don't support having descriptions because the Rust types are defined in external crates
--> schema:4:1
|
4 | scalar Uuid
| ^
aborting due to 4 errors
error[E0405]: cannot find trait `QueryFields` in this scope
--> $DIR/docs_on_special_case_scalars.rs:30:6
|
30 | impl QueryFields for Query {
| ^^^^^^^^^^^ not found in this scope
================================================
FILE: juniper-from-schema/tests/compile_fail/invalid_as_ref_type.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
asRefString: String! @juniper(ownership: "as_ref")
}
schema {
query: Query
}
}
pub struct Query;
impl QueryFields for Query {
fn field_as_ref_string(
&self,
executor: &Executor<Context>,
) -> FieldResult<String> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_fail/invalid_as_ref_type.stderr
================================================
error: proc macro panicked
--> $DIR/invalid_as_ref_type.rs:4:1
|
4 | / juniper_from_schema::graphql_schema! {
5 | | type Query {
6 | | asRefString: String! @juniper(ownership: "as_ref")
7 | | }
... |
11 | | }
12 | | }
| |_^
|
= help: message:
error: @juniper(ownership: "as_ref") is only supported on `Option` and `Vec` types
--> schema:1:14
|
1 | type Query { asRefString : String ! @ juniper(ownership : "as_ref") } schema
| ^
aborting due to previous error
error[E0405]: cannot find trait `QueryFields` in this scope
--> $DIR/invalid_as_ref_type.rs:16:6
|
16 | impl QueryFields for Query {
| ^^^^^^^^^^^ not found in this scope
================================================
FILE: juniper-from-schema/tests/compile_fail/invalid_date_time_scalar_directive.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
use chrono::prelude::*;
juniper_from_schema::graphql_schema! {
schema {
query: Query
}
type Query {
dateTime: DateTimeUtc! @juniper(ownership: "owned")
}
scalar DateTimeUtc @juniper(with_time_zone: "foobar")
}
pub struct Query;
impl QueryFields for Query {
fn field_date_time(&self, _: &Executor<Context>) -> FieldResult<NaiveDateTime> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_fail/invalid_date_time_scalar_directive.stderr
================================================
error: proc macro panicked
--> $DIR/invalid_date_time_scalar_directive.rs:6:1
|
6 | / juniper_from_schema::graphql_schema! {
7 | | schema {
8 | | query: Query
9 | | }
... |
15 | | scalar DateTimeUtc @juniper(with_time_zone: "foobar")
16 | | }
| |_^
|
= help: message:
error: Unsupported directive.
--> schema:3:1
|
3 | @ juniper(with_time_zone : "foobar")
| ^
Invalid type. Expected `Boolean`, got `String`
aborting due to previous error
error[E0405]: cannot find trait `QueryFields` in this scope
--> $DIR/invalid_date_time_scalar_directive.rs:20:6
|
20 | impl QueryFields for Query {
| ^^^^^^^^^^^ not found in this scope
================================================
FILE: juniper-from-schema/tests/compile_fail/invalid_juniper_directive_definition.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
string: String!
}
schema { query: Query }
directive @juniper(
ownership: Boolean,
infallible: String = "foo",
with_time_zone: [String] = false,
async: Boolean = true,
stream_type: String = null,
stream_item_infallible: Boolean = false,
bar: [Boolean]
) on FIELD
}
pub struct Query;
impl QueryFields for Query {
fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_fail/invalid_juniper_directive_definition.stderr
================================================
error: proc macro panicked
--> $DIR/invalid_juniper_directive_definition.rs:4:1
|
4 | / juniper_from_schema::graphql_schema! {
5 | | type Query {
6 | | string: String!
7 | | }
... |
19 | | ) on FIELD
20 | | }
| |_^
|
= help: message:
error: Invalid location for @juniper directive: `FIELD`
--> schema:1:59
|
1 | type Query { string : String ! } schema { query : Query } directive @
| ^
Location must be `FIELD_DEFINITION | SCALAR`
error: Missing `FIELD_DEFINITION` directive location for @juniper directive
--> schema:1:59
|
1 | type Query { string : String ! } schema { query : Query } directive @
| ^
Location must be `FIELD_DEFINITION | SCALAR`
error: Missing `SCALAR` directive location for @juniper directive
--> schema:1:59
|
1 | type Query { string : String ! } schema { query : Query } directive @
| ^
Location must be `FIELD_DEFINITION | SCALAR`
error: Missing default value for `ownership` argument. Must be `"borrowed"`
--> schema:2:9
|
2 | juniper(ownership : Boolean, infallible : String = "foo", with_time_zone :
| ^
error: `ownership` argument must have type `String`
--> schema:2:9
|
2 | juniper(ownership : Boolean, infallible : String = "foo", with_time_zone :
| ^
Got `Boolean`
error: Invalid default value for `infallible` argument. Must be `false`
--> schema:2:30
|
2 | juniper(ownership : Boolean, infallible : String = "foo", with_time_zone :
| ^
Got `"foo"`
error: `infallible` argument must have type `Boolean`
--> schema:2:30
|
2 | juniper(ownership : Boolean, infallible : String = "foo", with_time_zone :
| ^
Got `String`
error: Invalid default value for `with_time_zone` argument. Must be `true`
--> schema:2:59
|
2 | juniper(ownership : Boolean, infallible : String = "foo", with_time_zone :
| ^
Got `false`
error: `with_time_zone` argument must have type `Boolean`
--> schema:2:59
|
2 | juniper(ownership : Boolean, infallible : String = "foo", with_time_zone :
| ^
Got `[String]`
error: Invalid default value for `async` argument. Must be `false`
--> schema:3:27
|
3 | [String] = false, async : Boolean = true, stream_type : String = null,
| ^
Got `true`
error: Invalid default value for `stream_item_infallible` argument. Must be `true`
--> schema:4:9
|
4 | stream_item_infallible : Boolean = false, bar : [Boolean]) on FIELD
| ^
Got `false`
error: Invalid argument for @juniper directive: `bar`
--> schema:4:51
|
4 | stream_item_infallible : Boolean = false, bar : [Boolean]) on FIELD
| ^
Supported arguments are `ownership`, `infallible`, `with_time_zone`, `async`, `stream_item_infallible`, and `stream_type`
aborting due to 12 errors
error[E0405]: cannot find trait `QueryFields` in this scope
--> $DIR/invalid_juniper_directive_definition.rs:24:6
|
24 | impl QueryFields for Query {
| ^^^^^^^^^^^ not found in this scope
================================================
FILE: juniper-from-schema/tests/compile_fail/invalid_stream_return_type.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
ping: Boolean!
}
type Subscription {
users: User! @juniper(infallible: true, ownership: "owned", stream_type: "123")
}
type User {
id: ID!
name: String!
}
schema {
query: Query
subscription: Subscription
}
}
pub struct Query;
impl QueryFields for Query {
fn field_ping(&self, _: &Executor<Context>) -> FieldResult<&bool> {
todo!()
}
}
pub struct Subscription;
impl SubscriptionFields for Subscription {
fn field_users<'r, 'a>(
&self,
_: &Executor<'r, 'a, Context>,
_: &QueryTrail<'r, User, Walked>,
) -> Box<dyn juniper_from_schema::futures::Stream<Item = User> + Send + Unpin> {
Box::new(juniper_from_schema::futures::stream::iter(vec![]))
}
}
pub struct User {
id: ID,
name: String,
}
impl UserFields for User {
fn field_id(&self, _: &Executor<Context>) -> FieldResult<&ID> {
todo!()
}
fn field_name(&self, _: &Executor<Context>) -> FieldResult<&String> {
todo!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_fail/invalid_stream_return_type.stderr
================================================
error: proc macro panicked
--> $DIR/invalid_stream_return_type.rs:4:1
|
4 | / juniper_from_schema::graphql_schema! {
5 | | type Query {
6 | | ping: Boolean!
7 | | }
... |
21 | | }
22 | | }
| |_^
|
= help: message:
error: Invalid stream return type. This doesn't seem to be a valid Rust type
--> schema:3:5
|
3 | users : User ! @
| ^
expected one of: `for`, parentheses, `fn`, `unsafe`, `extern`, identifier, `::`, `<`, square brackets, `*`, `&`, `!`, `impl`, `_`, lifetime
aborting due to previous error
error[E0405]: cannot find trait `QueryFields` in this scope
--> $DIR/invalid_stream_return_type.rs:26:6
|
26 | impl QueryFields for Query {
| ^^^^^^^^^^^ not found in this scope
error[E0405]: cannot find trait `SubscriptionFields` in this scope
--> $DIR/invalid_stream_return_type.rs:34:6
|
34 | impl SubscriptionFields for Subscription {
| ^^^^^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `QueryTrail` in this scope
--> $DIR/invalid_stream_return_type.rs:38:13
|
38 | _: &QueryTrail<'r, User, Walked>,
| ^^^^^^^^^^ not found in this scope
|
help: consider importing this struct
|
1 | use juniper_from_schema::QueryTrail;
|
error[E0412]: cannot find type `Walked` in this scope
--> $DIR/invalid_stream_return_type.rs:38:34
|
38 | _: &QueryTrail<'r, User, Walked>,
| ^^^^^^ not found in this scope
|
help: consider importing this struct
|
1 | use juniper_from_schema::Walked;
|
error[E0405]: cannot find trait `UserFields` in this scope
--> $DIR/invalid_stream_return_type.rs:49:6
|
49 | impl UserFields for User {
| ^^^^^^^^^^ not found in this scope
================================================
FILE: juniper-from-schema/tests/compile_fail/scalar_with_built_in_name.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
juniper_from_schema::graphql_schema! {
schema {
query: Query
}
type Query {
// The directive makes the return value `FieldResult<String>`
// rather than the default `FieldResult<&String>`
helloWorld(name: String!): String! @juniper(ownership: "owned")
}
scalar String
}
pub struct Query;
impl QueryFields for Query {
fn field_hello_world(&self, executor: &Executor<Context>, name: String) -> FieldResult<String> {
todo!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_fail/scalar_with_built_in_name.stderr
================================================
error: proc macro panicked
--> $DIR/scalar_with_built_in_name.rs:4:1
|
4 | / juniper_from_schema::graphql_schema! {
5 | | schema {
6 | | query: Query
7 | | }
... |
15 | | scalar String
16 | | }
| |_^
|
= help: message:
error: You cannot declare scalars with names matching a built-in
--> schema:3:1
|
3 | scalar String
| ^
aborting due to previous error
error[E0405]: cannot find trait `QueryFields` in this scope
--> $DIR/scalar_with_built_in_name.rs:20:6
|
20 | impl QueryFields for Query {
| ^^^^^^^^^^^ not found in this scope
================================================
FILE: juniper-from-schema/tests/compile_fail/snake_cased_fields_on_input_object_types.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
field: String!
}
schema { query: Query }
input SomeInput {
snake_cased: String!
}
}
pub struct Query;
impl QueryFields for Query {
fn field_field(&self, _: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_fail/snake_cased_fields_on_input_object_types.stderr
================================================
error: proc macro panicked
--> $DIR/snake_cased_fields_on_input_object_types.rs:4:1
|
4 | / juniper_from_schema::graphql_schema! {
5 | | type Query {
6 | | field: String!
7 | | }
... |
13 | | }
14 | | }
| |_^
|
= help: message:
error: Field names must be camelCase, not snake_case
--> schema:2:3
|
2 | { snake_cased : String ! }
| ^
This is because Juniper always converts all field names to camelCase
aborting due to previous error
error[E0405]: cannot find trait `QueryFields` in this scope
--> $DIR/snake_cased_fields_on_input_object_types.rs:18:6
|
18 | impl QueryFields for Query {
| ^^^^^^^^^^^ not found in this scope
================================================
FILE: juniper-from-schema/tests/compile_fail/snake_cased_fields_on_interfaces.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
field: SomeInterface!
}
schema { query: Query }
interface SomeInterface {
snake_cased: String!
}
}
pub struct Query;
impl QueryFields for Query {
fn field_field(
&self,
_: &Executor<Context>,
_: &QueryTrail<SomeInterface, Walked>,
) -> FieldResult<&SomeInterface> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_fail/snake_cased_fields_on_interfaces.stderr
================================================
error: proc macro panicked
--> $DIR/snake_cased_fields_on_interfaces.rs:4:1
|
4 | / juniper_from_schema::graphql_schema! {
5 | | type Query {
6 | | field: SomeInterface!
7 | | }
... |
13 | | }
14 | | }
| |_^
|
= help: message:
error: Field names must be camelCase, not snake_case
--> schema:2:17
|
2 | SomeInterface { snake_cased : String ! }
| ^
This is because Juniper always converts all field names to camelCase
aborting due to previous error
error[E0405]: cannot find trait `QueryFields` in this scope
--> $DIR/snake_cased_fields_on_interfaces.rs:18:6
|
18 | impl QueryFields for Query {
| ^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `QueryTrail` in this scope
--> $DIR/snake_cased_fields_on_interfaces.rs:22:13
|
22 | _: &QueryTrail<SomeInterface, Walked>,
| ^^^^^^^^^^ not found in this scope
|
help: consider importing this struct
|
1 | use juniper_from_schema::QueryTrail;
|
error[E0412]: cannot find type `SomeInterface` in this scope
--> $DIR/snake_cased_fields_on_interfaces.rs:22:24
|
18 | impl QueryFields for Query {
| - help: you might be missing a type parameter: `<SomeInterface>`
...
22 | _: &QueryTrail<SomeInterface, Walked>,
| ^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `Walked` in this scope
--> $DIR/snake_cased_fields_on_interfaces.rs:22:39
|
22 | _: &QueryTrail<SomeInterface, Walked>,
| ^^^^^^ not found in this scope
|
help: consider importing this struct
|
1 | use juniper_from_schema::Walked;
|
error[E0412]: cannot find type `SomeInterface` in this scope
--> $DIR/snake_cased_fields_on_interfaces.rs:23:23
|
18 | impl QueryFields for Query {
| - help: you might be missing a type parameter: `<SomeInterface>`
...
23 | ) -> FieldResult<&SomeInterface> {
| ^^^^^^^^^^^^^ not found in this scope
================================================
FILE: juniper-from-schema/tests/compile_fail/snake_cased_fields_on_types.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
snake_cased: String!
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_snake_cased(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_fail/snake_cased_fields_on_types.stderr
================================================
error: proc macro panicked
--> $DIR/snake_cased_fields_on_types.rs:4:1
|
4 | / juniper_from_schema::graphql_schema! {
5 | | type Query {
6 | | snake_cased: String!
7 | | }
8 | |
9 | | schema { query: Query }
10 | | }
| |_^
|
= help: message:
error: Field names must be camelCase, not snake_case
--> schema:1:14
|
1 | type Query { snake_cased : String ! } schema { query : Query }
| ^
This is because Juniper always converts all field names to camelCase
aborting due to previous error
error[E0405]: cannot find trait `QueryFields` in this scope
--> $DIR/snake_cased_fields_on_types.rs:14:6
|
14 | impl QueryFields for Query {
| ^^^^^^^^^^^ not found in this scope
================================================
FILE: juniper-from-schema/tests/compile_fail/unknown_directive.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
string: String! @someDirectiveThatIsntNotSupported
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_fail/unknown_directive.stderr
================================================
error: proc macro panicked
--> $DIR/unknown_directive.rs:4:1
|
4 | / juniper_from_schema::graphql_schema! {
5 | | type Query {
6 | | string: String! @someDirectiveThatIsntNotSupported
7 | | }
8 | |
9 | | schema { query: Query }
10 | | }
| |_^
|
= help: message:
error: Unknown directive
--> schema:1:32
|
1 | type Query { string : String ! @ someDirectiveThatIsntNotSupported } schema
| ^
aborting due to previous error
error[E0405]: cannot find trait `QueryFields` in this scope
--> $DIR/unknown_directive.rs:14:6
|
14 | impl QueryFields for Query {
| ^^^^^^^^^^^ not found in this scope
================================================
FILE: juniper-from-schema/tests/compile_fail/unsupported_config.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
juniper_from_schema::graphql_schema_from_file!(
"../../../juniper-from-schema/tests/schemas/customizing_context_name.graphql",
foo: Foo
);
pub struct Query;
impl QueryFields for Query {
fn field_foo(&self, _: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_fail/unsupported_config.stderr
================================================
error: Unknown `graphql_schema_from_file` config `foo`
Supported configs are `error_type` and `context_type`
--> $DIR/unsupported_config.rs:6:5
|
6 | foo: Foo
| ^^^
error[E0405]: cannot find trait `QueryFields` in this scope
--> $DIR/unsupported_config.rs:11:6
|
11 | impl QueryFields for Query {
| ^^^^^^^^^^^ not found in this scope
================================================
FILE: juniper-from-schema/tests/compile_fail/uppercase_uuid.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
use uuid::Uuid;
juniper_from_schema::graphql_schema! {
schema {
query: Query
}
type Query {
uuid: UUID! @juniper(ownership: "owned")
}
scalar UUID
}
pub struct Query;
impl QueryFields for Query {
fn field_uuid(&self, _: &Executor<Context>) -> FieldResult<Uuid> {
Ok(Uuid::new_v4())
}
}
================================================
FILE: juniper-from-schema/tests/compile_fail/uppercase_uuid.stderr
================================================
error: proc macro panicked
--> $DIR/uppercase_uuid.rs:6:1
|
6 | / juniper_from_schema::graphql_schema! {
7 | | schema {
8 | | query: Query
9 | | }
... |
15 | | scalar UUID
16 | | }
| |_^
|
= help: message:
error: The UUID must be named `Uuid`
--> schema:2:50
|
2 | { uuid : UUID ! @ juniper(ownership : "owned") } scalar UUID
| ^
This is to be consistent with the naming the "uuid" crate
aborting due to previous error
error[E0405]: cannot find trait `QueryFields` in this scope
--> $DIR/uppercase_uuid.rs:20:6
|
20 | impl QueryFields for Query {
| ^^^^^^^^^^^ not found in this scope
================================================
FILE: juniper-from-schema/tests/compile_pass/async.rs
================================================
#![allow(
dead_code,
unused_mut,
unused_variables,
unused_must_use,
unused_imports
)]
include!("setup.rs");
use std::future::Future;
use std::task::Poll;
juniper_from_schema::graphql_schema! {
schema {
query: Query
}
type Query {
asyncPing: Boolean! @juniper(infallible: true, ownership: "owned", async: true)
syncPing: Boolean! @juniper(infallible: true, ownership: "owned", async: false)
}
type User implements Entity {
id: ID! @juniper(infallible: true, ownership: "owned", async: true)
}
interface Entity {
id: ID! @juniper(infallible: true, ownership: "owned", async: true)
}
}
pub struct Query;
#[juniper_from_schema::juniper::async_trait]
impl QueryFields for Query {
async fn field_async_ping<'s, 'r, 'a>(&'s self, _: &Executor<'r, 'a, Context>) -> bool {
ready(true).await
}
fn field_sync_ping(&self, _: &Executor<Context>) -> bool {
true
}
}
pub struct User;
#[juniper_from_schema::juniper::async_trait]
impl UserFields for User {
async fn field_id<'s, 'r, 'a>(&'s self, _: &Executor<'r, 'a, Context>) -> ID {
todo!()
}
}
// copied from std because it isn't stable yet
pub struct Ready<T>(Option<T>);
impl<T> Unpin for Ready<T> {}
impl<T> Future for Ready<T> {
type Output = T;
fn poll(mut self: Pin<&mut Self>, _cx: &mut std::task::Context<'_>) -> Poll<T> {
todo!()
}
}
pub fn ready<T>(t: T) -> Ready<T> {
todo!()
}
================================================
FILE: juniper-from-schema/tests/compile_pass/async_as_ref.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
schema {
query: Query
}
type Query {
find(id: ID!): User @juniper(ownership: "as_ref", async: true)
}
type User {
id: ID! @juniper(infallible: true)
}
}
pub struct Query;
#[juniper_from_schema::juniper::async_trait]
impl QueryFields for Query {
async fn field_find<'s, 'r, 'a>(
&'s self,
_: &Executor<'r, 'a, Context>,
trail: &QueryTrail<'r, User, Walked>,
id: ID,
) -> FieldResult<Option<&'s User>> {
todo!()
}
}
#[derive(Debug)]
pub struct User {
id: ID,
}
impl UserFields for User {
fn field_id(&self, _: &Executor<Context>) -> &ID {
todo!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/async_field_returning_type.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
use juniper_from_schema::*;
use url::Url;
juniper_from_schema::graphql_schema! {
schema {
query: Query
}
type Query {
find(id: ID!): User! @juniper(ownership: "owned", async: true)
}
type User {
id: ID! @juniper(infallible: true)
}
}
pub struct Query;
#[juniper_from_schema::juniper::async_trait]
impl QueryFields for Query {
async fn field_find<'s, 'r, 'a>(
&'s self,
_: &Executor<'r, 'a, Context>,
trail: &QueryTrail<'r, User, Walked>,
id: ID,
) -> FieldResult<User> {
todo!()
}
}
#[derive(Debug)]
pub struct User {
id: ID,
}
impl UserFields for User {
fn field_id(&self, _: &Executor<Context>) -> &ID {
todo!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/async_returning_reference.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
use juniper_from_schema::*;
use url::Url;
juniper_from_schema::graphql_schema! {
schema {
query: Query
}
type Query {
find(id: ID!): User! @juniper(async: true)
}
type User {
id: ID! @juniper(infallible: true)
}
}
pub struct Query;
#[juniper_from_schema::juniper::async_trait]
impl QueryFields for Query {
async fn field_find<'s, 'r, 'a>(
&'s self,
_: &Executor<'r, 'a, Context>,
trail: &QueryTrail<'r, User, Walked>,
id: ID,
) -> FieldResult<&'s User> {
todo!()
}
}
#[derive(Debug)]
pub struct User {
id: ID,
}
impl UserFields for User {
fn field_id(&self, _: &Executor<Context>) -> &ID {
todo!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/correct_executor_signature.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
field: Int!
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_field(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/custom_scalar.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
scalar Cursor
type Query {
field(arg: Cursor!): Cursor!
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_field<'a>(
&self,
executor: &Executor<Context>,
arg: Cursor,
) -> FieldResult<&Cursor> {
Cursor::new("123");
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/customizing_context_name.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema_from_file!(
"../../../juniper-from-schema/tests/schemas/customizing_context_name.graphql",
context_type: MyContext
);
pub struct MyContext;
impl juniper::Context for MyContext {}
pub struct Query;
impl QueryFields for Query {
fn field_foo(&self, _: &Executor<MyContext>) -> FieldResult<&String> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/customizing_the_error_type.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema_from_file!(
"../../../juniper-from-schema/tests/schemas/very_simple_schema.graphql",
error_type: MyError,
);
pub enum MyError {
Foo,
Bar,
}
impl juniper::IntoFieldError for MyError {
fn into_field_error(self) -> juniper::FieldError {
unimplemented!()
}
}
pub struct Query;
impl QueryFields for Query {
fn field_string(&self, executor: &Executor<Context>) -> Result<&String, MyError> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/dates_and_times.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
use chrono::{naive::NaiveDate, prelude::*};
juniper_from_schema::graphql_schema! {
schema {
query: Query
}
type Query {
date: Date! @juniper(ownership: "owned")
dateTime: DateTimeUtc! @juniper(ownership: "owned")
}
scalar Date
scalar DateTimeUtc
}
pub struct Query;
impl QueryFields for Query {
fn field_date(&self, _: &Executor<Context>) -> FieldResult<NaiveDate> {
unimplemented!()
}
fn field_date_time(&self, _: &Executor<Context>) -> FieldResult<DateTime<Utc>> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/directive_definitions_are_allowed.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
string: String!
}
schema { query: Query }
directive @foo(bar: [String!]!) on FIELD
}
pub struct Query;
impl QueryFields for Query {
fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/empty_mutations.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
string: String!
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
fn this_should_compile() {
let _ = juniper::execute_sync(
"query Foo { string }",
None,
&Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()),
&Variables::new(),
&Context,
)
.unwrap();
}
================================================
FILE: juniper-from-schema/tests/compile_pass/enums.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
enum YesNo {
YES
NO
NOT_SURE
}
type Query {
yesNo(arg: YesNo): YesNo!
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_yes_no(
&self,
executor: &Executor<Context>,
arg: Option<YesNo>,
) -> FieldResult<&YesNo> {
let _: YesNo = YesNo::No;
let _: YesNo = YesNo::Yes;
let _: YesNo = YesNo::NotSure;
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/field_args.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
single(arg: Int!): Int!
multiple(one: Int!, two: String, three: [Float]): Int!
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_single(&self, executor: &Executor<Context>, arg: i32) -> FieldResult<&i32> {
unimplemented!()
}
fn field_multiple(
&self,
executor: &Executor<Context>,
one: i32,
two: Option<String>,
three: Option<Vec<Option<f64>>>,
) -> FieldResult<&i32> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/infallible_directive.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
schema {
query: Query
}
type Query {
unowned: String! @juniper(infallible: true)
owned: String! @juniper(ownership: "owned", infallible: true)
ownedReordered: String! @juniper(infallible: true, ownership: "owned")
}
type User implements Entity {
id: ID! @juniper(infallible: true)
}
interface Entity {
id: ID! @juniper(infallible: true)
}
}
pub struct Query;
impl QueryFields for Query {
fn field_unowned(&self, _: &Executor<Context>) -> &String {
unimplemented!()
}
fn field_owned(&self, _: &Executor<Context>) -> String {
unimplemented!()
}
fn field_owned_reordered(&self, _: &Executor<Context>) -> String {
unimplemented!()
}
}
pub struct User;
impl UserFields for User {
fn field_id(&self, _: &Executor<Context>) -> &ID {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/input_object.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
usersAtLocation(coordinate: Coordinate): Boolean!
}
input Coordinate {
lat: Int!
long: Int!
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_users_at_location(
&self,
executor: &Executor<Context>,
coordinate: Option<Coordinate>,
) -> FieldResult<&bool> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/input_object_clone.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
usersAtLocation(coordinate: Coordinate): Boolean!
}
input Coordinate {
lat: Int!
long: Int!
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_users_at_location(
&self,
executor: &Executor<Context>,
coordinate: Option<Coordinate>,
) -> FieldResult<&bool> {
let coord = coordinate.clone();
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/input_objects_have_public_fields.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
mod schema {
use super::*;
juniper_from_schema::graphql_schema! {
type Query {
usersAtLocation(coordinate: Coordinate!): Boolean!
}
input Coordinate {
lat: Int!
long: Int!
}
schema { query: Query }
}
}
pub struct Query;
impl schema::QueryFields for Query {
fn field_users_at_location(
&self,
executor: &Executor<Context>,
coordinate: schema::Coordinate,
) -> FieldResult<&bool> {
coordinate.lat;
coordinate.long;
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/naive_date_time.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
use chrono::prelude::*;
juniper_from_schema::graphql_schema! {
schema {
query: Query
}
type Query {
dateTime: DateTimeUtc! @juniper(ownership: "owned")
}
scalar DateTimeUtc @juniper(with_time_zone: false)
}
pub struct Query;
impl QueryFields for Query {
fn field_date_time(&self, _: &Executor<Context>) -> FieldResult<NaiveDateTime> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/non_null_list_non_null_items.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
field: [Int!]!
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_field(&self, executor: &Executor<Context>) -> FieldResult<&Vec<i32>> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/non_null_list_nullable_items.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
field: [Int]!
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_field(&self, executor: &Executor<Context>) -> FieldResult<&Vec<Option<i32>>> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/nullable_list_non_null_items.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
field: [Int!]
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_field(&self, executor: &Executor<Context>) -> FieldResult<&Option<Vec<i32>>> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/nullable_list_nullable_items.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
field: [Int]
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_field(
&self,
executor: &Executor<Context>,
) -> FieldResult<&Option<Vec<Option<i32>>>> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/ownership_attributes.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
borrowedString: String! @juniper(ownership: "borrowed")
ownedString: String! @juniper(ownership: "owned")
asRefString: String @juniper(ownership: "as_ref")
}
schema {
query: Query
}
}
pub struct Query;
impl QueryFields for Query {
fn field_borrowed_string(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
fn field_owned_string(&self, executor: &Executor<Context>) -> FieldResult<String> {
unimplemented!()
}
fn field_as_ref_string<'s>(
&'s self,
executor: &Executor<Context>,
) -> FieldResult<Option<&'s String>> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/query_trail.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
user: User!
}
type User {
id: Int!
club: Club
club2: Club!
}
type Club {
id: Int!
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_user(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<User, Walked>,
) -> FieldResult<&User> {
trail.club().walk();
trail.club2().walk();
trail.club2().id() == true;
unimplemented!()
}
}
pub struct User {
id: i32,
}
impl UserFields for User {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
unimplemented!()
}
fn field_club(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Club, Walked>,
) -> FieldResult<&Option<Club>> {
unimplemented!()
}
fn field_club2(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Club, Walked>,
) -> FieldResult<&Club> {
unimplemented!()
}
}
pub struct Club {
id: i32,
}
impl ClubFields for Club {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/query_trail_methods_for_interfaces.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
posts: [Post!]! @juniper(ownership: "owned")
}
type Post {
comments: [Comment!]! @juniper(ownership: "owned")
}
interface Entity {
id: Int! @juniper(ownership: "owned")
country: Country! @juniper(ownership: "owned")
}
type User implements Entity {
country: Country! @juniper(ownership: "owned")
id: Int! @juniper(ownership: "owned")
}
type Country {
id: Int! @juniper(ownership: "owned")
}
type Comment {
author: Entity! @juniper(ownership: "owned")
id: Int! @juniper(ownership: "owned")
}
schema {
query: Query
}
}
pub struct Query;
impl QueryFields for Query {
fn field_posts(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Post, Walked>,
) -> FieldResult<Vec<Post>> {
unimplemented!()
}
}
pub struct Post {
comments: Vec<Comment>,
}
impl PostFields for Post {
fn field_comments(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Comment, Walked>,
) -> FieldResult<Vec<Comment>> {
unimplemented!()
}
}
pub struct Comment {
id: i32,
}
impl CommentFields for Comment {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
unimplemented!()
}
fn field_author(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Entity, Walked>,
) -> FieldResult<Entity> {
if trail.id() {
//
}
if trail.country().id() {
//
}
unimplemented!()
}
}
pub struct User {
id: i32,
}
impl UserFields for User {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
unimplemented!()
}
fn field_country(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Country, Walked>,
) -> FieldResult<Country> {
unimplemented!()
}
}
pub struct Country {
id: i32,
}
impl CountryFields for Country {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/query_trail_methods_for_union_types.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
posts: [Post!]! @juniper(ownership: "owned")
}
type Post {
comments: [Comment!]! @juniper(ownership: "owned")
}
union Entity = User | Company
type User {
country: Country! @juniper(ownership: "owned")
id: Int! @juniper(ownership: "owned")
}
type Company {
countryOfOperation: Country! @juniper(ownership: "owned")
id: Int! @juniper(ownership: "owned")
name: String! @juniper(ownership: "owned")
}
type Country {
id: Int! @juniper(ownership: "owned")
}
type Comment {
author: Entity! @juniper(ownership: "owned")
id: Int! @juniper(ownership: "owned")
}
schema {
query: Query
}
}
pub struct Query;
impl QueryFields for Query {
fn field_posts(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Post, Walked>,
) -> FieldResult<Vec<Post>> {
unimplemented!()
}
}
pub struct Post {
comments: Vec<Comment>,
}
impl PostFields for Post {
fn field_comments(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Comment, Walked>,
) -> FieldResult<Vec<Comment>> {
unimplemented!()
}
}
pub struct Comment {
id: i32,
}
impl CommentFields for Comment {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
unimplemented!()
}
fn field_author(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Entity, Walked>,
) -> FieldResult<Entity> {
let _: bool = trail.id();
let _: bool = trail.country().id();
let _: QueryTrail<Country, NotWalked> = trail.country();
let _: bool = trail.country_of_operation().id();
let _: QueryTrail<Country, NotWalked> = trail.country_of_operation();
let _: bool = trail.name();
unimplemented!()
}
}
pub struct User {
id: i32,
}
impl UserFields for User {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
unimplemented!()
}
fn field_country(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Country, Walked>,
) -> FieldResult<Country> {
unimplemented!()
}
}
pub struct Company {
id: i32,
}
impl CompanyFields for Company {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
unimplemented!()
}
fn field_name(&self, executor: &Executor<Context>) -> FieldResult<String> {
unimplemented!()
}
fn field_country_of_operation(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Country, Walked>,
) -> FieldResult<Country> {
unimplemented!()
}
}
pub struct Country {
id: i32,
}
impl CountryFields for Country {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/returning_references.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema_from_file!(
"../../../juniper-from-schema/tests/schemas/returning_references.graphql"
);
pub struct Query;
impl QueryFields for Query {
fn field_user_nullable(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<User, Walked>,
id: i32,
) -> FieldResult<Option<User>> {
Ok(find_user(id))
}
fn field_user_non_null(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<User, Walked>,
id: i32,
) -> FieldResult<User> {
Ok(find_user(id).unwrap())
}
}
pub struct User {
id: i32,
name: String,
name_nullable: Option<String>,
}
impl UserFields for User {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
Ok(&self.id)
}
fn field_name_nullable(
&self,
executor: &Executor<Context>,
) -> FieldResult<Option<String>> {
Ok(self.name_nullable.clone())
}
fn field_name_non_null(&self, executor: &Executor<Context>) -> FieldResult<&String> {
Ok(&self.name)
}
}
fn find_user(id: i32) -> Option<User> {
Some(User {
id,
name: "Bob".to_string(),
name_nullable: None,
})
}
================================================
FILE: juniper-from-schema/tests/compile_pass/setup.rs
================================================
use juniper::{EmptyMutation, EmptySubscription, Executor, FieldResult, Variables, ID};
use std::pin::Pin;
pub struct Context;
impl juniper::Context for Context {}
fn main() {}
#[allow(dead_code)]
fn __use_all_the_imports(
_: EmptyMutation<()>,
_: Executor<()>,
_: FieldResult<(), ()>,
_: Variables,
_: ID,
_: EmptySubscription<()>,
_: Pin<()>,
) {
}
================================================
FILE: juniper-from-schema/tests/compile_pass/simple_non_null_scalars.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
string: String!
float: Float!
int: Int!
boolean: Boolean!
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
fn field_float(&self, executor: &Executor<Context>) -> FieldResult<&f64> {
unimplemented!()
}
fn field_int(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
unimplemented!()
}
fn field_boolean(&self, executor: &Executor<Context>) -> FieldResult<&bool> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/simple_nullable_scalars.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
string: String
float: Float
int: Int
boolean: Boolean
}
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&Option<String>> {
unimplemented!()
}
fn field_float(&self, executor: &Executor<Context>) -> FieldResult<&Option<f64>> {
unimplemented!()
}
fn field_int(&self, executor: &Executor<Context>) -> FieldResult<&Option<i32>> {
unimplemented!()
}
fn field_boolean(&self, executor: &Executor<Context>) -> FieldResult<&Option<bool>> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/url.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
use url::Url;
juniper_from_schema::graphql_schema! {
schema {
query: Query
}
type Query {
url: Url! @juniper(ownership: "owned")
}
scalar Url
}
pub struct Query;
impl QueryFields for Query {
fn field_url(&self, _: &Executor<Context>) -> FieldResult<Url> {
let url = Url::parse("https://example.com").unwrap();
Ok(url)
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/uuid.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("setup.rs");
use uuid::Uuid;
juniper_from_schema::graphql_schema! {
schema {
query: Query
}
type Query {
uuid: Uuid! @juniper(ownership: "owned")
}
scalar Uuid
}
pub struct Query;
impl QueryFields for Query {
fn field_uuid(&self, _: &Executor<Context>) -> FieldResult<Uuid> {
Ok(Uuid::new_v4())
}
}
================================================
FILE: juniper-from-schema/tests/compile_pass/valid_juniper_directive_definition.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
include!("../compile_pass/setup.rs");
juniper_from_schema::graphql_schema! {
type Query {
string: String!
}
schema { query: Query }
directive @juniper(
ownership: String = "borrowed",
infallible: Boolean = false,
with_time_zone: Boolean = true,
async: Boolean = false,
stream_item_infallible: Boolean = true,
stream_type: String = null
) on FIELD_DEFINITION | SCALAR
}
pub struct Query;
impl QueryFields for Query {
fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&String> {
unimplemented!()
}
}
================================================
FILE: juniper-from-schema/tests/converting_query_trails_test.rs
================================================
#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]
use juniper::{EmptyMutation, Executor, FieldResult, Variables};
use juniper_from_schema::{graphql_schema, graphql_schema_from_file};
pub struct Context;
impl juniper::Context for Context {}
graphql_schema! {
type Query {
entities: [Entity!]! @juniper(ownership: "owned")
search(query: String!): [SearchResult!]! @juniper(ownership: "owned")
}
interface Entity {
id: Int! @juniper(ownership: "owned")
name: String!
}
type User implements Entity {
id: Int! @juniper(ownership: "owned")
name: String!
}
union SearchResult = User
schema {
query: Query
}
}
pub struct Query;
impl QueryFields for Query {
fn field_entities(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Entity, Walked>,
) -> FieldResult<Vec<Entity>> {
verify_entity_query_trail(trail);
verify_user_query_trail(&trail.downcast());
Ok(vec![])
}
fn field_search(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<SearchResult, Walked>,
_query: String,
) -> FieldResult<Vec<SearchResult>> {
verify_search_result_query_trail(trail);
verify_user_query_trail(&trail.downcast());
Ok(vec![])
}
}
fn verify_entity_query_trail(trail: &QueryTrail<Entity, Walked>) {
if !trail.id() {
panic!("Entity.id missing from trail")
}
}
fn verify_search_result_query_trail(trail: &QueryTrail<SearchResult, Walked>) {
if !trail.id() {
panic!("id missing from trail")
}
}
fn verify_user_query_trail(trail: &QueryTrail<User, Walked>) {
if !trail.id() {
panic!("User.id missing from trail")
}
}
pub struct User {
id: i32,
name: String,
}
impl UserFields for User {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
Ok(self.id)
}
fn field_name(&self, executor: &Executor<Context>) -> FieldResult<&String> {
Ok(&self.name)
}
}
#[test]
fn test_converting_interface_trails() {
query(
r#"
query {
entities {
id
}
}
"#,
);
}
#[test]
#[should_panic]
fn test_converting_interface_trails_negative() {
query(
r#"
query {
entities {
name
}
}
"#,
);
}
#[test]
fn test_converting_union_trails() {
query(
r#"
query {
search(query: "foo") {
... on User {
id
}
}
}
"#,
);
}
#[test]
#[should_panic]
fn test_converting_union_trails_negative() {
query(
r#"
query {
search(query: "foo") {
... on User {
name
}
}
}
"#,
);
}
fn query(query: &str) {
let ctx = Context;
let (juniper_value, _errors) = juniper::execute_sync(
query,
None,
&Schema::new(
Query,
juniper::EmptyMutation::new(),
juniper::EmptySubscription::new(),
),
&Variables::new(),
&ctx,
)
.unwrap();
}
================================================
FILE: juniper-from-schema/tests/default_argument_values_test.rs
================================================
#![allow(clippy::let_unit_value)]
#![allow(dead_code, unused_variables, unused_imports)]
#[macro_use]
extern crate juniper;
use assert_json_diff::assert_json_include;
use juniper::{Executor, FieldResult, Variables};
use juniper_from_schema::{graphql_schema, graphql_schema_from_file};
use serde_json::{self, json, Value};
use std::collections::HashMap;
graphql_schema! {
type Query {
int(arg: Int = 1): Int! @juniper(ownership: "owned")
float(arg: Float = 1.5): Float! @juniper(ownership: "owned")
string(arg: String = "foo"): String! @juniper(ownership: "owned")
boolean(arg: Boolean = true): Boolean! @juniper(ownership: "owned")
list(arg: [Int!] = [1, 2, 3]): [Int!]! @juniper(ownership: "owned")
enumeration(arg: Unit = METER): Unit! @juniper(ownership: "owned")
object(arg: CoordinateIn = { lat: 1.0, long: 2.0 }): CoordinateOut! @juniper(ownership: "owned")
objectNullable(arg: Pagination = { pageSize: null }): Int @juniper(ownership: "owned")
objectNullableSet(arg: Pagination = { pageSize: 1 }): Int @juniper(ownership: "owned")
objectNullablePartial(arg: A = { a: "a arg" }): [String]! @juniper(ownership: "owned")
objectNullableNesting(arg: B = { c: { x: 1 } }): [Int]! @juniper(ownership: "owned")
}
input CoordinateIn {
lat: Float!
long: Float!
}
type CoordinateOut {
lat: Float!
long: Float!
}
input Pagination {
pageSize: Int
}
input A {
a: String
b: String
}
input B {
c: C
}
input C {
x: Int
}
enum Unit { METER FOOT }
schema { query: Query }
}
pub struct Query;
impl QueryFields for Query {
fn field_int(&self, _: &Executor<Context>, arg: i32) -> FieldResult<i32> {
Ok(arg)
}
fn field_float(&self, _: &Executor<Context>, arg: f64) -> FieldResult<f64> {
Ok(arg)
}
fn field_string(&self, _: &Executor<Context>, arg: String) -> FieldResult<String> {
Ok(arg)
}
fn field_boolean(&self, _: &Executor<Context>, arg: bool) -> FieldResult<bool> {
Ok(arg)
}
fn field_list(&self, _: &Executor<Context>, arg: Vec<i32>) -> FieldResult<Vec<i32>> {
Ok(arg)
}
fn field_enumeration(&self, _: &Executor<Context>, arg: Unit) -> FieldResult<Unit> {
Ok(arg)
}
fn field_object(
&self,
_: &Executor<Context>,
_: &QueryTrail<CoordinateOut, Walked>,
arg: CoordinateIn,
) -> FieldResult<CoordinateOut> {
Ok(CoordinateOut {
lat: arg.lat,
long: arg.long,
})
}
fn field_object_nullable(
&self,
_: &Executor<Context>,
arg: Pagination,
) -> FieldResult<Option<i32>> {
Ok(arg.page_size)
}
fn field_object_nullable_set(
&self,
_: &Executor<Context>,
arg: Pagination,
) -> FieldResult<Option<i32>> {
Ok(arg.page_size)
}
fn field_object_nullable_partial(
&self,
_: &Executor<Context>,
arg: A,
) -> FieldResult<Vec<Option<String>>> {
Ok(vec![arg.a, arg.b])
}
fn field_object_nullable_nesting(
&self,
_: &Executor<Context>,
b: B,
) -> FieldResult<Vec<Option<i32>>> {
Ok(vec![b.c.and_then(|c| c.x)])
}
}
pub struct CoordinateOut {
pub lat: f64,
pub long: f64,
}
impl CoordinateOutFields for CoordinateOut {
fn field_lat(&self, _: &Executor<Context>) -> FieldResult<&f64> {
Ok(&self.lat)
}
fn field_long(&self, _: &Executor<Context>) -> FieldResult<&f64> {
Ok(&self.long)
}
}
type Context = ();
#[test]
fn test_int() {
let value = run_query(r#"query { int }"#);
assert_json_include!(actual: value, expected: json!({ "int": 1 }));
let value = run_query(r#"query { int(arg: 1337) }"#);
assert_json_include!(actual: value, expected: json!({ "int": 1337 }));
}
#[test]
fn test_float() {
let value = run_query(r#"query { float }"#);
assert_json_include!(actual: value, expected: json!({ "float": 1.5 }));
let value = run_query(r#"query { float(arg: 1337.5) }"#);
assert_json_include!(actual: value, expected: json!({ "float": 1337.5 }));
}
#[test]
fn test_string() {
let value = run_query(r#"query { string }"#);
assert_json_include!(actual: value, expected: json!({ "string": "foo" }));
let value = run_query(r#"query { string(arg: "bar") }"#);
assert_json_include!(actual: value, expected: json!({ "string": "bar" }));
}
#[test]
fn test_boolean() {
let value = run_query(r#"query { boolean }"#);
assert_json_include!(actual: value, expected: json!({ "boolean": true }));
let value = run_query(r#"query { boolean(arg: false) }"#);
assert_json_include!(actual: value, expected: json!({ "boolean": false }));
}
#[test]
fn test_list() {
let value = run_query(r#"query { list }"#);
assert_json_include!(actual: value, expected: json!({ "list": [1, 2, 3] }));
let value = run_query(r#"query { list(arg: [1337]) }"#);
assert_json_include!(actual: value, expected: json!({ "list": [1337] }));
}
#[test]
fn test_enumeration() {
let value = run_query(r#"query { enumeration }"#);
assert_json_include!(actual: value, expected: json!({ "enumeration": "METER" }));
let value = run_query(r#"query { enumeration(arg: FOOT) }"#);
assert_json_include!(actual: value, expected: json!({ "enumeration": "FOOT" }));
}
#[test]
fn test_object() {
let value = run_query(r#"query { object { lat long } }"#);
assert_json_include!(
actual: value,
expected: json!({ "object": { "lat": 1.0, "long": 2.0 } })
);
let value = run_query(r#"query { object(arg: { lat: 10.0, long: 20.0 }) { lat long } }"#);
assert_json_include!(
actual: value,
expected: json!({ "object": { "lat": 10.0, "long": 20.0 } })
);
}
#[test]
fn test_object_nullable() {
let value = run_query(r#"query { objectNullable }"#);
assert_json_include!(actual: value, expected: json!({ "objectNullable": null }));
let value = run_query(r#"query { objectNullable(arg: { pageSize: 1 }) }"#);
assert_json_include!(actual: value, expected: json!({ "objectNullable": 1 }));
}
#[test]
fn test_object_nullable_set() {
let value = run_query(r#"query { objectNullableSet }"#);
assert_json_include!(actual: value, expected: json!({ "objectNullableSet": 1 }));
let value = run_query(r#"query { objectNullableSet(arg: { pageSize: 2 }) }"#);
assert_json_include!(actual: value, expected: json!({ "objectNullableSet": 2 }));
let value = run_query(r#"query { objectNullableSet(arg: { pageSize: null }) }"#);
assert_json_include!(
actual: value,
expected: json!({ "objectNullableSet": null })
);
}
#[test]
fn test_object_partial() {
let value = run_query(r#"query { objectNullablePartial }"#);
assert_json_include!(
actual: value,
expected: json!({ "objectNullablePartial": ["a arg", null] })
);
let value = run_query(r#"query { objectNullablePartial(arg: { a: "a field" }) }"#);
assert_json_include!(
actual: value,
expected: json!({ "objectNullablePartial": ["a field", null] })
);
let value = run_query(r#"query { objectNullablePartial(arg: { b: "b field" }) }"#);
assert_json_include!(
actual: value,
expected: json!({ "objectNullablePartial": [null, "b field"] })
);
let value =
run_query(r#"query { objectNullablePartial(arg: { a: "a field", b: "b field" }) }"#);
assert_json_include!(
actual: value,
expected: json!({ "objectNullablePartial": ["a field", "b field"] })
);
}
#[test]
fn test_object_nesting() {
let value = run_query(r#"query { objectNullableNesting }"#);
assert_json_include!(
actual: value,
expected: json!({ "objectNullableNesting": [1] })
);
}
fn run_query(query: &str) -> Value {
let ctx = ();
let (res, _errors) = juniper::execute_sync(
query,
None,
&Schema::new(
Query,
juniper::EmptyMutation::new(),
juniper::EmptySubscription::new(),
),
&Variables::new(),
&ctx,
)
.unwrap();
let json = serde_json::from_str(&serde_json::to_string(&res).unwrap()).unwrap();
println!("--- <json> -----------------");
println!("{}", serde_json::to_string_pretty(&json).unwrap());
println!("--- </json> -----------------");
json
}
================================================
FILE: juniper-from-schema/tests/doc_test.rs
================================================
#![recursion_limit = "128"]
#![allow(dead_code)]
#![allow(unused_braces)]
#![deny(deprecated)]
use assert_json_diff::assert_json_include;
use juniper::{Executor, FieldResult, Variables, ID};
use juniper_from_schema::graphql_schema_from_file;
use serde_json::{self, json, Value};
// The query that GraphiQL runs to inspect the schema
static SCHEMA_INTROSPECTION_QUERY: &str = r#"
query IntrospectionQuery {
__schema {
queryType {
name
}
mutationType {
name
}
subscriptionType {
name
}
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type {
...TypeRef
}
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
"#;
graphql_schema_from_file!("tests/schemas/doc_test.graphql");
pub struct Query;
impl QueryFields for Query {
fn field_query_field(&self, _: &Executor<Context>, _: InputType) -> FieldResult<&SomeScalar> {
unimplemented!()
}
fn field_entity(
&self,
_: &Executor<Context>,
_: &QueryTrail<Entity, Walked>,
) -> FieldResult<&Entity> {
unimplemented!()
}
fn field_deprecated_field(&self, _: &Executor<Context>) -> FieldResult<&ID> {
unimplemented!()
}
fn field_deprecated_field2(&self, _: &Executor<Context>) -> FieldResult<&ID> {
unimplemented!()
}
fn field_search(
&self,
_: &Executor<Context>,
_: &QueryTrail<SearchResult, Walked>,
_: String,
) -> FieldResult<&Vec<SearchResult>> {
unimplemented!()
}
}
pub struct User {
id: ID,
user_type: UserType,
}
impl UserFields for User {
fn field_id(&self, _: &Executor<Context>) -> FieldResult<&ID> {
unimplemented!()
}
fn field_user_type(&self, _: &Executor<Context>) -> FieldResult<&UserType> {
unimplemented!()
}
fn field_interface_field(&self, _: &Executor<Context>, _: ID) -> FieldResult<&ID> {
unimplemented!()
}
}
use futures::stream::Stream;
use std::pin::Pin;
pub struct Subscription;
impl SubscriptionFields for Subscription {
fn field_subscription_field(
&self,
_: &Executor<Context>,
_: InputType,
) -> Pin<Box<dyn Stream<Item = SomeScalar> + Send>> {
Box::pin(futures::stream::iter(vec![]))
}
}
pub struct Context;
impl juniper::Context for Context {}
#[test]
fn test_docs() {
let mut json = introspect_schema()["__schema"]["types"]
.as_array()
.unwrap()
.clone()
.into_iter()
.filter(|type_| !type_["name"].as_str().unwrap().starts_with("__"))
.collect::<Vec<_>>();
json.sort_by_key(|key| key["name"].as_str().unwrap().to_string());
let json = serde_json::Value::Array(json);
println!("{}", serde_json::to_string_pretty(&json).unwrap());
assert_json_include!(
actual: json,
expected:
json!([
{ "name": "Boolean" },
{
"name": "Entity",
"description": "Entity desc",
"fields": [
{
"name": "id",
"description": "Entity id desc",
"isDeprecated": true,
"deprecationReason": null,
},
{
"name": "interfaceField",
"description": null,
"isDeprecated": false,
"deprecationReason": null,
"args": [
{
"name": "arg",
// docs on interface field arguments are not supported in
// juniper
"description": null,
}
]
},
],
},
{ "name": "ID" },
{
"name": "InputType",
"description": "InputType desc",
"inputFields": [
{
"name": "id",
"description": "id desc",
},
]
},
{
"name": "Query",
"description": "Root query type",
"fields": [
{
"name": "queryField",
"description": "queryField desc",
"isDeprecated": false,
"args": [
{
"name": "queryFieldArg",
"description": "queryFieldArg desc",
},
],
},
{
"name": "deprecatedField",
"description": "deprecatedField desc",
"isDeprecated": true,
"deprecationReason": null,
},
{
"name": "deprecatedField2",
"description": "deprecatedField2 desc",
"isDeprecated": true,
"deprecationReason": "because reasons",
},
],
},
{
"name": "SearchResult",
"description": "SearchResult desc",
},
{
"name": "SomeScalar",
"description": "SomeScalar scalar desc",
},
{ "name": "String" },
{
"name": "Subscription",
"description": "Root subscription type",
"fields": [
{
"name": "subscriptionField",
"description": "subscriptionField desc",
"isDeprecated": false,
"args": [
{
"name": "subscriptionFieldArg",
"description": "subscriptionFieldArg desc",
},
],
},
],
},
{ "name": "User" },
{
"name": "UserType",
"description": "UserType desc",
"enumValues": [
{
"name": "REAL",
"description": "REAL desc",
"deprecationReason": "because reasons",
"isDeprecated": true,
},
{
"name": "BOT",
"description": "BOT desc",
"deprecationReason": null,
"isDeprecated": false,
},
{
"name": "OTHER",
"description": "OTHER desc",
"deprecationReason": null,
"isDeprecated": true,
},
],
},
])
);
}
fn introspect_schema() -> Value {
let ctx = Context;
let (juniper_value, _errors) = juniper::execute_sync(
SCHEMA_INTROSPECTION_QUERY,
None,
&Schema::new(Query, juniper::EmptyMutation::new(), Subscription),
&Variables::new(),
&ctx,
)
.unwrap();
let json: Value =
serde_json::from_str(&serde_json::to_string(&juniper_value).unwrap()).unwrap();
println!("{}", serde_json::to_string_pretty(&json).unwrap());
json
}
================================================
FILE: juniper-from-schema/tests/end_to_end_test.rs
================================================
#![allow(dead_code, unused_variables, unused_imports)]
#![allow(unused_braces)]
use assert_json_diff::assert_json_include;
use juniper::{Executor, FieldResult, Variables, ID};
use juniper_from_schema::{graphql_schema, graphql_schema_from_file};
use serde_json::{self, json, Value};
use std::collections::HashMap;
graphql_schema_from_file!("tests/schemas/complex_schema.graphql");
pub struct Query;
impl QueryFields for Query {
fn field_hero(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Character, Walked>,
episode: Option<Episode>,
) -> FieldResult<Option<Character>> {
let hero = episode.and_then(|episode| {
let luke = executor
.context()
.db
.humans
.get(&"1")
.map(|h| Character::from(h.clone()));
match episode {
Episode::Newhope => luke,
Episode::Empire => luke,
Episode::Jedi => luke,
}
});
Ok(hero)
}
fn field_search(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<SearchResult, Walked>,
text: Option<String>,
) -> FieldResult<Option<Vec<SearchResult>>> {
let results = text.map(|text| {
executor
.context()
.db
.humans
.clone()
.into_iter()
.map(|(_, human)| human)
.filter(|human| human.name.contains(&text))
.map(SearchResult::from)
.collect::<Vec<_>>()
});
Ok(results)
}
}
pub struct Mutation;
impl MutationFields for Mutation {
fn field_create_review(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<Review, Walked>,
episode: Option<Episode>,
review: ReviewInput,
) -> FieldResult<Option<Review>> {
let review = Review {
episode,
stars: review.stars,
commentary: review.commentary,
favorite_color: review.favorite_color,
};
// the fact that everything type checks is test enough, we don't need to actually insert
// this review
Ok(Some(review))
}
}
pub struct Review {
episode: Option<Episode>,
stars: i32,
commentary: Option<String>,
favorite_color: Option<ColorInput>,
}
impl ReviewFields for Review {
fn field_episode(&self, executor: &Executor<Context>) -> FieldResult<&Option<Episode>> {
Ok(&self.episode)
}
fn field_stars(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
Ok(&self.stars)
}
fn field_commentary(&self, executor: &Executor<Context>) -> FieldResult<&Option<String>> {
Ok(&self.commentary)
}
}
#[derive(Clone)]
pub struct Human {
id: &'static str,
name: String,
}
impl HumanFields for Human {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<ID> {
Ok(ID::new(self.id))
}
fn field_name(&self, executor: &Executor<Context>) -> FieldResult<&String> {
Ok(&self.name)
}
}
#[derive(Clone)]
pub struct Droid {
id: &'static str,
name: String,
}
impl DroidFields for Droid {
fn field_id(&self, executor: &Executor<Context>) -> FieldResult<ID> {
Ok(ID::new(self.id))
}
fn field_name(&self, executor: &Executor<Context>) -> FieldResult<&String> {
Ok(&self.name)
}
}
pub struct Context {
db: Db,
}
impl juniper::Context for Context {}
pub struct Db {
humans: HashMap<&'static str, Human>,
}
#[test]
fn query_hero() {
let value = run_query(r#"query { hero(episode: NEWHOPE) { id name } }"#);
assert_json_include!(
actual: value,
expected: json!({
"hero": {
"id": "1",
"name": "Luke Skywalker",
}
})
);
let value = run_query(r#"query { hero(episode: EMPIRE) { id name } }"#);
assert_json_include!(
actual: value,
expected: json!({
"hero": {
"id": "1",
"name": "Luke Skywalker",
}
})
);
let value = run_query(r#"query { hero(episode: JEDI) { id name } }"#);
assert_json_include!(
actual: value,
expected: json!({
"hero": {
"id": "1",
"name": "Luke Skywalker",
}
})
);
}
#[test]
fn search() {
let value = run_query(
r#"
query {
search(text: "Luke") {
... on Human {
id name
}
... on Droid {
id name
}
}
}
"#,
);
assert_json_include!(
actual: value,
expected: json!({
"search": [
{ "id": "1", "name": "Luke Skywalker" },
]
})
);
}
fn run_query(query: &str) -> Value {
let db = Db {
humans: maplit::hashmap! {
"1" => Human { id: "1", name: "Luke Skywalker".to_string() },
},
};
let ctx = Context { db };
let (res, _errors) = juniper::execute_sync(
query,
None,
&Schema::new(Query, Mutation, juniper::EmptySubscription::new()),
&Variables::new(),
&ctx,
)
.unwrap();
serde_json::from_str(&serde_json::to_string(&res).unwrap()).unwrap()
}
================================================
FILE: juniper-from-schema/tests/launchpad.rs
================================================
// this file can be used for testing/debugging things before moving them into a trybuild test
#![allow(warnings)]
use futures::stream::Stream;
use juniper::{EmptyMutation, Executor, FieldResult, Variables, ID};
use std::pin::Pin;
pub struct Context;
impl juniper::Context for Context {}
fn main() {}
================================================
FILE: juniper-from-schema/tests/query_trail_arguments.rs
================================================
#![allow(clippy::too_many_arguments)]
#![allow(dead_code, unused_variables, unused_imports)]
#[macro_use]
extern crate juniper;
use assert_json_diff::assert_json_include;
use chrono::prelude::*;
use juniper::{Executor, FieldResult, Variables, ID};
use juniper_from_schema::{graphql_schema, graphql_schema_from_file};
use serde_json::{self, json, Value};
use std::collections::HashMap;
use url::Url;
use uuid::Uuid;
graphql_schema! {
schema {
query: Query
}
type Query {
a: A! @juniper(ownership: "owned")
}
type A {
b: B! @juniper(ownership: "owned")
}
type B {
c: C! @juniper(ownership: "owned")
}
type C {
fieldWithArg(
stringArg: String!
nullableArg: String
nullableArg2: String
intArg: Int!
floatArg: Float!
boolArg: Boolean!
listArg: [Int!]!
enumArg: Color!
objectArg: InputObject!
cursorArg: Cursor!
idArg: ID!
urlArg: Url!
uuidArg: Uuid!
dateArg: Date!
dateTimeArg: DateTimeUtc!
defaultArg: String = "value set in schema"
defaultArg2: String = "error"
): String! @juniper(ownership: "owned")
fieldWithArgReturningType(
stringArg: String!
): D! @juniper(ownership: "owned")
}
type D {
value: String! @juniper(ownership: "owned")
}
input InputObject {
value: String!
}
enum Color {
RED
BLUE
}
scalar Cursor
scalar Url
scalar Uuid
scalar Date
scalar DateTimeUtc
}
pub struct Query;
impl QueryFields for Query {
fn field_a(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<A, Walked>,
) -> FieldResult<A> {
if let Some(c) = trail.b().c().walk() {
assert_eq!("foo".to_string(), c.field_with_arg_args().string_arg());
assert_eq!(None, c.field_with_arg_args().nullable_arg());
assert_eq!(
Some("bar".to_string()),
c.field_with_arg_args().nullable_arg2()
);
assert_eq!(1, c.field_with_arg_args().int_arg());
assert_eq!("2.5", c.field_with_arg_args().float_arg().to_string());
assert_eq!(false, c.field_with_arg_args().bool_arg());
assert_eq!(vec![1, 2, 3], c.field_with_arg_args().list_arg());
assert_eq!(Color::Red, c.field_with_arg_args().enum_arg());
assert_eq!(
"baz".to_string(),
c.field_with_arg_args().object_arg().value
);
assert_eq!(
Cursor("cursor-value".to_string()),
c.field_with_arg_args().cursor_arg()
);
assert_eq!(ID::new("id-value"), c.field_with_arg_args().id_arg());
assert_eq!(
Url::parse("https://example.net").unwrap(),
c.field_with_arg_args().url_arg()
);
assert_eq!(
Uuid::parse_str("46ebd0ee-0e6d-43c9-b90d-ccc35a913f3e").unwrap(),
c.field_with_arg_args().uuid_arg()
);
assert_eq!(
NaiveDate::parse_from_str("2019-01-01", "%Y-%m-%d").unwrap(),
c.field_with_arg_args().date_arg()
);
assert_eq!(
DateTime::parse_from_rfc3339("1996-12-19T16:39:57-08:00").unwrap(),
c.field_with_arg_args().date_time_arg()
);
assert_eq!(
"value set in schema".to_string(),
c.field_with_arg_args().default_arg()
);
assert_eq!(
"value set in query".to_string(),
c.field_with_arg_args().default_arg2()
);
assert_eq!(
"qux".to_string(),
c.field_with_arg_returning_type_args().string_arg()
);
}
Ok(A)
}
}
pub struct A;
impl AFields for A {
fn field_b(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<B, Walked>,
) -> FieldResult<B> {
Ok(B)
}
}
pub struct B;
impl BFields for B {
fn field_c(
&self,
executor: &Executor<Context>,
trail: &QueryTrail<C, Walked>,
) -> FieldResult<C> {
Ok(C)
}
}
pub struct C;
impl CFields for C {
fn field_field_with_arg(
&self,
executor: &Executor<Context>,
_: String,
_: Option<String>,
_: Option<String>,
_: i32,
_: f64,
_: bool,
_: Vec<i32>,
_: Color,
_: InputObject,
_: Cursor,
_: ID,
_: Url,
_: Uuid,
_: NaiveDate,
_: DateTime<Utc>,
_: String,
_: String,
) -> FieldResult<String> {
Ok(String::new())
}
fn field_field_with_arg_returning_type(
&self,
executor: &Executor<Context>,
_: &QueryTrail<D, Walked>,
_: String,
) -> FieldResult<D> {
Ok(D)
}
}
pub struct D;
impl DFields for D {
fn field_value(&self, executor: &Executor<Context>) -> FieldResult<String> {
Ok(String::new())
}
}
#[test]
fn scalar_values() {
let value = run_query(
r#"query {
a {
b {
c {
fieldWithArg(
stringArg: "foo",
nullableArg: null,
nullableArg2: "bar",
intArg: 1,
floatArg: 2.5,
boolArg: false,
listArg: [1, 2, 3],
enumArg: RED,
objectArg: { value: "baz" },
cursorArg: "cursor-value",
idArg: "id-value",
urlArg: "https://example.net",
uuidArg: "46ebd0ee-0e6d-43c9-b90d-ccc35a913f3e",
dateArg: "2019-01-01",
dateTimeArg: "1996-12-19T16:39:57-08:00",
defaultArg2: "value set in query",
)
fieldWithArgReturningType(
stringArg: "qux",
) {
value
}
}
}
}
}"#,
);
assert_json_include!(
actual: value,
expected: json!({
"a": { "b": { "c": {} } }
})
);
}
type Context = ();
fn run_query(query: &str) -> Value {
let (res, _errors) = juniper::execute_sync(
query,
None,
&Schema::new(
Query,
juniper::EmptyMutation::new(),
juniper::EmptySubscription::new(),
),
&Variables::new(),
&(),
)
.unwrap();
let json = serde_json::from_str(&serde_json::to_string(&res).unwrap()).unwrap();
println!("--- <json> -----------------");
println!("{}", serde_json::to_string_pretty(&json).unwrap());
println!("--- </json> -----------------");
json
}
================================================
FILE: juniper-from-schema/tests/schemas/complex_schema.graphql
================================================
# From https://github.com/apollographql/starwars-server/blob/master/data/swapiSchema.js
# Missing:
# - subscription type
schema {
query: Query
mutation: Mutation
}
"The query type, represents all of the entry points into our object graph"
type Query {
hero(episode: Episode): Character @juniper(ownership: "owned")
search(text: String): [SearchResult!] @juniper(ownership: "owned")
}
"The mutation type, represents all updates we can make to our data"
type Mutation {
createReview(episode: Episode, review: ReviewInput!): Review @juniper(ownership: "owned")
}
"The episodes in the Star Wars trilogy"
enum Episode {
"Star Wars Episode IV: A New Hope, released in 1977."
NEWHOPE
"Star Wars Episode V: The Empire Strikes Back, released in 1980."
EMPIRE
"Star Wars Episode VI: Return of the Jedi, released in 1983."
JEDI
}
"A character from the Star Wars universe"
interface Character {
"""
The ID of the character
"""
id: ID! @juniper(ownership: "owned")
"The name of the character"
name: String!
}
"A humanoid creature from the Star Wars universe"
type Human implements Character {
"""
The ID of the human
"""
id: ID! @juniper(ownership: "owned")
"What this human calls themselves"
name: String!
}
"A humanoid creature from the Star Wars universe"
type Droid implements Character {
"""
The ID of the human
"""
id: ID! @juniper(ownership: "owned")
"What this human calls themselves"
name: String!
}
union SearchResult = Human | Droid
input ReviewInput {
"0-5 stars"
stars: Int!
"Comment about the movie, optional"
commentary: String
"Favorite color, optional"
favoriteColor: ColorInput
}
"The input object sent when passing in a color"
input ColorInput {
red: Int!
green: Int!
blue: Int!
}
"Represents a review for a movie"
type Review {
"The movie"
episode: Episode
"The number of stars this review gave, 1-5"
stars: Int!
"Comment about the movie"
commentary: String
}
================================================
FILE: juniper-from-schema/tests/schemas/customizing_context_name.graphql
================================================
type Query {
foo: String!
}
schema {
query: Query
}
================================================
FILE: juniper-from-schema/tests/schemas/doc_schema.graphql
================================================
schema {
query: Query
mutation: Mutation
}
type Query {
helloWorld(name: String!): String! @juniper(ownership: "owned")
}
type Mutation {
noop: Boolean!
}
================================================
FILE: juniper-from-schema/tests/schemas/doc_test.graphql
================================================
schema {
query: Query
subscription: Subscription
}
"Root query type"
type Query {
"queryField desc"
queryField(
"queryFieldArg desc"
queryFieldArg: InputType!
): SomeScalar!
"deprecatedField desc"
deprecatedField: ID! @deprecated
"deprecatedField2 desc"
deprecatedField2: ID! @deprecated(reason: "because reasons")
entity: Entity!
search(query: String!): [SearchResult!]!
}
"Root subscription type"
type Subscription {
"subscriptionField desc"
subscriptionField(
"subscriptionFieldArg desc"
subscriptionFieldArg: InputType!
): SomeScalar! @juniper(ownership: "owned", infallible: true)
}
"SomeScalar scalar desc"
scalar SomeScalar
"InputType desc"
input InputType {
"id desc"
id: ID!
}
type User implements Entity {
id: ID!
userType: UserType!
interfaceField(
"interface field arg desc"
arg: ID!
): ID!
}
"Entity desc"
interface Entity {
"Entity id desc"
id: ID! @deprecated
interfaceField(
"interface field arg desc"
arg: ID!
): ID!
}
"UserType desc"
enum UserType {
"REAL desc"
REAL @deprecated(reason: "because reasons")
"BOT desc"
BOT
"OTHER desc"
OTHER @deprecated
}
"SearchResult desc"
union SearchResult = User
================================================
FILE: juniper-from-schema/tests/schemas/original_complex.graphql
================================================
# From https://github.com/apollographql/starwars-server/blob/master/data/swapiSchema.js
# Missing:
# - subscription type
schema {
query: Query
mutation: Mutation
}
"The query type, represents all of the entry points into our object graph"
type Query {
hero(episode: Episode): Character
reviews(episode: Episode!): [Review]
search(text: String): [SearchResult]
character(id: ID!): Character
droid(id: ID!): Droid
human(id: ID!): Human
starship(id: ID!): Starship
}
"The mutation type, represents all updates we can make to our data"
type Mutation {
createReview(episode: Episode, review: ReviewInput!): Review
}
"The episodes in the Star Wars trilogy"
enum Episode {
"Star Wars Episode IV: A New Hope, released in 1977."
NEWHOPE
"Star Wars Episode V: The Empire Strikes Back, released in 1980."
EMPIRE
"Star Wars Episode VI: Return of the Jedi, released in 1983."
JEDI
}
"A character from the Star Wars universe"
interface Character {
"The ID of the character"
id: ID!
"The name of the character"
name: String!
"The friends of the character, or an empty list if they have none"
friends: [Character]
"The friends of the character exposed as a connection with edges"
friendsConnection(first: Int, after: ID): FriendsConnection!
"The movies this character appears in"
appearsIn: [Episode]!
}
"Units of height"
enum LengthUnit {
"The standard unit around the world"
METER
"Primarily used in the United States"
FOOT
}
"A humanoid creature from the Star Wars universe"
type Human implements Character {
"The ID of the human"
id: ID!
"What this human calls themselves"
name: String!
"The home planet of the human, or null if unknown"
homePlanet: String
"Height in the preferred unit, default is meters"
height(unit: LengthUnit = METER): Float
"Mass in kilograms, or null if unknown"
mass: Float
"This human's friends, or an empty list if they have none"
friends: [Character]
"The friends of the human exposed as a connection with edges"
friendsConnection(first: Int, after: ID): FriendsConnection!
"The movies this human appears in"
appearsIn: [Episode]!
"A list of starships this person has piloted, or an empty list if none"
starships: [Starship]
}
"An autonomous mechanical character in the Star Wars universe"
type Droid implements Character {
"The ID of the droid"
id: ID!
"What others call this droid"
name: String!
"This droid's friends, or an empty list if they have none"
friends: [Character]
"The friends of the droid exposed as a connection with edges"
friendsConnection(first: Int, after: ID): FriendsConnection!
"The movies this droid appears in"
appearsIn: [Episode]!
"This droid's primary function"
primaryFunction: String
}
"A connection object for a character's friends"
type FriendsConnection {
"The total number of friends"
totalCount: Int
"The edges for each of the character's friends."
edges: [FriendsEdge]
"A list of the friends, as a convenience when edges are not needed."
friends: [Character]
"Information for paginating this connection"
pageInfo: PageInfo!
}
"An edge object for a character's friends"
type FriendsEdge {
"A cursor used for pagination"
cursor: ID!
"The character represented by this friendship edge"
node: Character
}
"Information for paginating this connection"
type PageInfo {
startCursor: ID
endCursor: ID
hasNextPage: Boolean!
}
"Represents a review for a movie"
type Review {
"The movie"
episode: Episode
"The number of stars this review gave, 1-5"
stars: Int!
"Comment about the movie"
commentary: String
}
"The input object sent when someone is creating a new review"
input ReviewInput {
"0-5 stars"
stars: Int!
"Comment about the movie, optional"
commentary: String
"Favorite color, optional"
favorite_color: ColorInput
}
"The input objec
gitextract_45z7vqcr/ ├── .github/ │ └── workflows/ │ └── ci.yml ├── .gitignore ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE ├── README.md ├── bin/ │ ├── release │ └── run_all_examples ├── generate-subscription-tests/ │ ├── Cargo.toml │ ├── generated_files/ │ │ └── .gitkeep │ └── src/ │ └── main.rs ├── juniper-from-schema/ │ ├── Cargo.toml │ ├── README.md │ ├── examples/ │ │ ├── async.rs │ │ ├── default_argument_values.rs │ │ ├── enumeration_types.rs │ │ ├── hello_world.rs │ │ ├── input_types.rs │ │ ├── interface.rs │ │ ├── query_trails.rs │ │ ├── subscription.rs │ │ └── union_types.rs │ ├── src/ │ │ └── lib.rs │ └── tests/ │ ├── compile_fail/ │ │ ├── docs_on_special_case_scalars.rs │ │ ├── docs_on_special_case_scalars.stderr │ │ ├── invalid_as_ref_type.rs │ │ ├── invalid_as_ref_type.stderr │ │ ├── invalid_date_time_scalar_directive.rs │ │ ├── invalid_date_time_scalar_directive.stderr │ │ ├── invalid_juniper_directive_definition.rs │ │ ├── invalid_juniper_directive_definition.stderr │ │ ├── invalid_stream_return_type.rs │ │ ├── invalid_stream_return_type.stderr │ │ ├── scalar_with_built_in_name.rs │ │ ├── scalar_with_built_in_name.stderr │ │ ├── snake_cased_fields_on_input_object_types.rs │ │ ├── snake_cased_fields_on_input_object_types.stderr │ │ ├── snake_cased_fields_on_interfaces.rs │ │ ├── snake_cased_fields_on_interfaces.stderr │ │ ├── snake_cased_fields_on_types.rs │ │ ├── snake_cased_fields_on_types.stderr │ │ ├── unknown_directive.rs │ │ ├── unknown_directive.stderr │ │ ├── unsupported_config.rs │ │ ├── unsupported_config.stderr │ │ ├── uppercase_uuid.rs │ │ └── uppercase_uuid.stderr │ ├── compile_pass/ │ │ ├── async.rs │ │ ├── async_as_ref.rs │ │ ├── async_field_returning_type.rs │ │ ├── async_returning_reference.rs │ │ ├── correct_executor_signature.rs │ │ ├── custom_scalar.rs │ │ ├── customizing_context_name.rs │ │ ├── customizing_the_error_type.rs │ │ ├── dates_and_times.rs │ │ ├── directive_definitions_are_allowed.rs │ │ ├── empty_mutations.rs │ │ ├── enums.rs │ │ ├── field_args.rs │ │ ├── infallible_directive.rs │ │ ├── input_object.rs │ │ ├── input_object_clone.rs │ │ ├── input_objects_have_public_fields.rs │ │ ├── naive_date_time.rs │ │ ├── non_null_list_non_null_items.rs │ │ ├── non_null_list_nullable_items.rs │ │ ├── nullable_list_non_null_items.rs │ │ ├── nullable_list_nullable_items.rs │ │ ├── ownership_attributes.rs │ │ ├── query_trail.rs │ │ ├── query_trail_methods_for_interfaces.rs │ │ ├── query_trail_methods_for_union_types.rs │ │ ├── returning_references.rs │ │ ├── setup.rs │ │ ├── simple_non_null_scalars.rs │ │ ├── simple_nullable_scalars.rs │ │ ├── url.rs │ │ ├── uuid.rs │ │ └── valid_juniper_directive_definition.rs │ ├── converting_query_trails_test.rs │ ├── default_argument_values_test.rs │ ├── doc_test.rs │ ├── end_to_end_test.rs │ ├── launchpad.rs │ ├── query_trail_arguments.rs │ ├── schemas/ │ │ ├── complex_schema.graphql │ │ ├── customizing_context_name.graphql │ │ ├── doc_schema.graphql │ │ ├── doc_test.graphql │ │ ├── original_complex.graphql │ │ ├── returning_references.graphql │ │ └── very_simple_schema.graphql │ ├── subscriptions/ │ │ ├── fail/ │ │ │ ├── stream_item_type_not_in_subscription_field.rs │ │ │ ├── stream_item_type_not_in_subscription_field.stderr │ │ │ ├── stream_type_not_in_subscription_field.rs │ │ │ ├── stream_type_not_in_subscription_field.stderr │ │ │ ├── subscriptions_cannot_implement_interfaces.rs │ │ │ └── subscriptions_cannot_implement_interfaces.stderr │ │ ├── pass/ │ │ │ ├── ownership_owned_infallible_false_async_false_stream_type_UserStream_stream_item_infallible_false.rs │ │ │ ├── ownership_owned_infallible_false_async_false_stream_type_UserStream_stream_item_infallible_true.rs │ │ │ ├── ownership_owned_infallible_false_async_false_stream_type_default_stream_item_infallible_false.rs │ │ │ ├── ownership_owned_infallible_false_async_false_stream_type_default_stream_item_infallible_true.rs │ │ │ ├── ownership_owned_infallible_false_async_true_stream_type_UserStream_stream_item_infallible_false.rs │ │ │ ├── ownership_owned_infallible_false_async_true_stream_type_UserStream_stream_item_infallible_true.rs │ │ │ ├── ownership_owned_infallible_false_async_true_stream_type_default_stream_item_infallible_false.rs │ │ │ ├── ownership_owned_infallible_false_async_true_stream_type_default_stream_item_infallible_true.rs │ │ │ ├── ownership_owned_infallible_true_async_false_stream_type_UserStream_stream_item_infallible_false.rs │ │ │ ├── ownership_owned_infallible_true_async_false_stream_type_UserStream_stream_item_infallible_true.rs │ │ │ ├── ownership_owned_infallible_true_async_false_stream_type_default_stream_item_infallible_false.rs │ │ │ ├── ownership_owned_infallible_true_async_false_stream_type_default_stream_item_infallible_true.rs │ │ │ ├── ownership_owned_infallible_true_async_true_stream_type_UserStream_stream_item_infallible_false.rs │ │ │ ├── ownership_owned_infallible_true_async_true_stream_type_UserStream_stream_item_infallible_true.rs │ │ │ ├── ownership_owned_infallible_true_async_true_stream_type_default_stream_item_infallible_false.rs │ │ │ └── ownership_owned_infallible_true_async_true_stream_type_default_stream_item_infallible_true.rs │ │ └── subscription_setup.rs │ └── version-numbers.rs ├── juniper-from-schema-build/ │ ├── Cargo.toml │ └── src/ │ └── lib.rs ├── juniper-from-schema-build-tests/ │ ├── basic/ │ │ ├── Cargo.toml │ │ ├── build.rs │ │ └── src/ │ │ └── lib.rs │ └── file/ │ ├── Cargo.toml │ ├── build.rs │ ├── schema.graphql │ └── src/ │ └── lib.rs ├── juniper-from-schema-code-gen/ │ ├── Cargo.toml │ └── src/ │ ├── ast_pass/ │ │ ├── code_gen_pass/ │ │ │ ├── gen_query_trails.rs │ │ │ └── mod.rs │ │ ├── directive_parsing.rs │ │ ├── error.rs │ │ ├── mod.rs │ │ ├── schema_visitor.rs │ │ └── validations.rs │ └── lib.rs ├── juniper-from-schema-proc-macro/ │ ├── Cargo.toml │ ├── README.md │ ├── src/ │ │ ├── lib.rs │ │ └── parse_input.rs │ └── tests/ │ └── version-numbers.rs └── rustfmt.toml
SYMBOL INDEX (757 symbols across 99 files)
FILE: generate-subscription-tests/src/main.rs
function main (line 10) | fn main() {
FILE: juniper-from-schema-build-tests/basic/build.rs
function main (line 1) | fn main() {
FILE: juniper-from-schema-build-tests/basic/src/lib.rs
type Context (line 8) | pub struct Context;
type Query (line 13) | pub struct Query;
method field_ping (line 16) | fn field_ping(&self, _: &Executor<Context>) -> FieldResult<&bool> {
FILE: juniper-from-schema-build-tests/file/build.rs
function main (line 1) | fn main() {
FILE: juniper-from-schema-build-tests/file/src/lib.rs
type Context (line 8) | pub struct Context;
type Query (line 13) | pub struct Query;
method field_ping (line 16) | fn field_ping(&self, _: &Executor<()>) -> Result<&bool, MyError> {
type MyError (line 22) | pub struct MyError;
method into_field_error (line 25) | fn into_field_error(self) -> FieldError<S> {
FILE: juniper-from-schema-build/src/lib.rs
function compile_schema_literal (line 60) | pub fn compile_schema_literal(schema: &str) -> Result<(), Box<dyn Error>> {
function configure_for_schema_literal (line 67) | pub fn configure_for_schema_literal(schema: &str) -> CodeGen {
function compile_file (line 76) | pub fn compile_file<P: AsRef<Path>>(path: P) -> Result<(), Box<dyn Error...
function configure_for_file (line 83) | pub fn configure_for_file<P: AsRef<Path>>(path: P) -> CodeGen {
type CodeGen (line 96) | pub struct CodeGen {
method context_type (line 114) | pub fn context_type(mut self, context_type: &str) -> Self {
method error_type (line 124) | pub fn error_type(mut self, error_type: &str) -> Self {
method compile (line 130) | pub fn compile(self) -> Result<(), Box<dyn Error>> {
type SchemaLocation (line 103) | enum SchemaLocation {
FILE: juniper-from-schema-code-gen/src/ast_pass/code_gen_pass/gen_query_trails.rs
type QueryTrailCodeGenPass (line 17) | struct QueryTrailCodeGenPass<'pass, 'doc> {
function gen_query_trails (line 24) | pub fn gen_query_trails(&mut self, doc: &'doc Document<'doc, &'doc str>)...
function gen_query_trail (line 58) | fn gen_query_trail(&mut self) {
function gen_from_default_scalar_value (line 79) | fn gen_from_default_scalar_value(&mut self) {
function gen_from_look_ahead_value (line 143) | fn gen_from_look_ahead_value(&mut self) {
function gen_field_walk_methods (line 334) | fn gen_field_walk_methods(&mut self, obj: InternalQueryTrailNode<'doc>) {
function gen_conversion_methods (line 389) | fn gen_conversion_methods(
function error_msg_if_field_types_dont_overlap (line 429) | fn error_msg_if_field_types_dont_overlap(&mut self, union: &'doc UnionTy...
function gen_field_walk_method (line 460) | fn gen_field_walk_method(
function gen_args_query_trail (line 551) | fn gen_args_query_trail(
function gen_argument_look_ahead_methods (line 620) | fn gen_argument_look_ahead_methods(
function visit_object_type (line 702) | fn visit_object_type(&mut self, obj: &'doc ObjectType<'doc, &'doc str>) {
function visit_interface_type (line 706) | fn visit_interface_type(&mut self, interface: &'doc InterfaceType<'doc, ...
function visit_union_type (line 710) | fn visit_union_type(&mut self, union: &'doc UnionType<'doc, &'doc str>) {
type FieldWalkMethod (line 720) | struct FieldWalkMethod {
type HashFieldByName (line 729) | struct HashFieldByName<'a>(&'a Field<'a, &'a str>);
method eq (line 732) | fn eq(&self, other: &HashFieldByName) -> bool {
method hash (line 740) | fn hash<H: Hasher>(&self, state: &mut H) {
type InternalQueryTrailNode (line 746) | enum InternalQueryTrailNode<'a> {
function name (line 753) | fn name(&self) -> Ident {
function fields (line 761) | fn fields(&self) -> Vec<&'a Field<'a, &'a str>> {
function build_union_fields_set (line 773) | fn build_union_fields_set<'d>(
function build_fields_map (line 790) | fn build_fields_map<'a>(
function test_fails_to_generate_query_trail_for_unions_where_fields_dont_overlap (line 815) | fn test_fails_to_generate_query_trail_for_unions_where_fields_dont_overl...
FILE: juniper-from-schema-code-gen/src/ast_pass/code_gen_pass/mod.rs
type CodeGenPass (line 18) | pub struct CodeGenPass<'doc> {
function new (line 35) | pub fn new(
function gen_juniper_code (line 58) | pub fn gen_juniper_code(
function validate_doc (line 107) | fn validate_doc(&mut self, doc: &'doc schema::Document<'doc, &'doc str>) {
function check_for_errors (line 123) | fn check_for_errors(&self) -> Result<(), BTreeSet<Error>> {
method emit_error (line 133) | fn emit_error(&mut self, pos: Pos, kind: ErrorKind) {
function visit_schema_definition (line 139) | fn visit_schema_definition(&mut self, node: &'doc schema::SchemaDefiniti...
function visit_directive_definition (line 188) | fn visit_directive_definition(
function visit_scalar_type (line 197) | fn visit_scalar_type(&mut self, node: &'doc schema::ScalarType<'doc, &'d...
function visit_object_type (line 242) | fn visit_object_type(&mut self, node: &'doc schema::ObjectType<'doc, &'d...
function visit_interface_type (line 291) | fn visit_interface_type(&mut self, node: &'doc schema::InterfaceType<'do...
function visit_union_type (line 327) | fn visit_union_type(&mut self, node: &'doc schema::UnionType<'doc, &'doc...
function visit_enum_type (line 365) | fn visit_enum_type(&mut self, node: &'doc schema::EnumType<'doc, &'doc s...
function visit_input_object_type (line 408) | fn visit_input_object_type(&mut self, node: &'doc schema::InputObjectTyp...
function visit_scalar_type_extension (line 458) | fn visit_scalar_type_extension(
function visit_object_type_extension (line 465) | fn visit_object_type_extension(
function visit_interface_type_extension (line 472) | fn visit_interface_type_extension(
function visit_union_type_extension (line 479) | fn visit_union_type_extension(
function visit_enum_type_extension (line 486) | fn visit_enum_type_extension(
function visit_input_object_type_extension (line 493) | fn visit_input_object_type_extension(
function graphql_field_to_rust_field (line 502) | fn graphql_field_to_rust_field(
function graphql_type_to_rust_type (line 576) | fn graphql_type_to_rust_type(
function quote_value (line 681) | fn quote_value(
function quote_object_value (line 727) | fn quote_object_value(
function validate_juniper_directive_definition (line 789) | fn validate_juniper_directive_definition(
function validate_directive_for_field (line 1019) | fn validate_directive_for_field(
type Either (line 1054) | enum Either<A, B> {
method to_tokens (line 1064) | fn to_tokens(&self, tokens: &mut TokenStream) {
type Type (line 1073) | enum Type {
method is_nullable (line 1085) | fn is_nullable(&self) -> bool {
method supports_as_ref (line 1089) | fn supports_as_ref(&self) -> bool {
method remove_one_layer_of_nullability_by_value (line 1102) | fn remove_one_layer_of_nullability_by_value(self) -> Box<Type> {
method remove_one_layer_of_nullability (line 1109) | fn remove_one_layer_of_nullability(&self) -> &Type {
method kind (line 1116) | fn kind(&self) -> TypeKind {
method innermost_type (line 1129) | fn innermost_type(&self) -> &Type {
method to_tokens (line 1144) | fn to_tokens(&self, tokens: &mut TokenStream) {
type Output (line 1176) | struct Output {}
type Scalar (line 1179) | struct Scalar<'doc> {
method to_tokens (line 1185) | fn to_tokens(&self, tokens: &mut TokenStream) {
type Object (line 1244) | struct Object<'doc> {
method to_tokens (line 1253) | fn to_tokens(&self, tokens: &mut TokenStream) {
function fields_trait_name (line 1311) | fn fields_trait_name(name: &Ident) -> Ident {
type Field (line 1316) | struct Field<'doc> {
function to_tokens_for_graphql_object_impl (line 1327) | fn to_tokens_for_graphql_object_impl<'a>(
function to_tokens_for_trait (line 1337) | fn to_tokens_for_trait<'a>(&'a self) -> FieldToTokensTrait<'a, 'doc> {
function to_tokens_for_interface (line 1341) | fn to_tokens_for_interface<'a>(&'a self) -> FieldToTokensInterface<'a, '...
function to_tokens_for_interface_impl (line 1345) | fn to_tokens_for_interface_impl<'a>(
function to_tokens_for_subscription_impl (line 1355) | fn to_tokens_for_subscription_impl<'a>(
function to_tokens_for_subscription_trait (line 1365) | fn to_tokens_for_subscription_trait<'a>(
function trait_field_name (line 1371) | fn trait_field_name(&self) -> Ident {
function asyncness (line 1375) | fn asyncness(&self) -> Option<Token![async]> {
function awaitness (line 1383) | fn awaitness(&self) -> Option<TokenStream> {
function return_type_not_wrapped_in_result (line 1391) | fn return_type_not_wrapped_in_result(&self) -> syn::Type {
function full_return_type (line 1408) | fn full_return_type(&self) -> syn::Type {
function full_stream_return_type (line 1416) | fn full_stream_return_type(&self) -> syn::Type {
function stream_item_type (line 1441) | fn stream_item_type(&self) -> syn::Type {
function query_trail_type (line 1455) | fn query_trail_type(&self) -> &Type {
function query_trail_param (line 1459) | fn query_trail_param(&self) -> Option<TokenStream> {
type FieldToTokensGraphqlObject (line 1473) | struct FieldToTokensGraphqlObject<'a, 'doc> {
method to_tokens (line 1480) | fn to_tokens(&self, tokens: &mut TokenStream) {
type FieldToTokensTrait (line 1568) | struct FieldToTokensTrait<'a, 'doc> {
method to_tokens (line 1573) | fn to_tokens(&self, tokens: &mut TokenStream) {
type FieldToTokensInterface (line 1605) | struct FieldToTokensInterface<'a, 'doc> {
method to_tokens (line 1610) | fn to_tokens(&self, tokens: &mut TokenStream) {
type FieldToTokensInterfaceImpl (line 1652) | struct FieldToTokensInterfaceImpl<'a, 'doc> {
method to_tokens (line 1658) | fn to_tokens(&self, tokens: &mut TokenStream) {
type FieldToTokensForSubscriptionImpl (line 1735) | struct FieldToTokensForSubscriptionImpl<'a, 'doc> {
method to_tokens (line 1741) | fn to_tokens(&self, tokens: &mut TokenStream) {
type FieldToTokensForSubscriptionTrait (line 1845) | struct FieldToTokensForSubscriptionTrait<'a, 'doc> {
method to_tokens (line 1850) | fn to_tokens(&self, tokens: &mut TokenStream) {
type FieldArg (line 1879) | struct FieldArg<'doc> {
function to_tokens_for_graphql_object_impl (line 1888) | fn to_tokens_for_graphql_object_impl<'a>(&'a self) -> FieldArgToTokensGr...
function to_tokens_for_trait (line 1892) | fn to_tokens_for_trait<'a>(&'a self) -> FieldArgsToTokensTrait<'a, 'doc> {
function to_tokens_for_interface (line 1896) | fn to_tokens_for_interface<'a>(&'a self) -> FieldArgsToTokensInterface<'...
type FieldArgToTokensGraphqlObject (line 1901) | struct FieldArgToTokensGraphqlObject<'a, 'doc>(&'a FieldArg<'doc>);
method to_tokens (line 1904) | fn to_tokens(&self, tokens: &mut TokenStream) {
type FieldArgsToTokensTrait (line 1919) | struct FieldArgsToTokensTrait<'a, 'doc>(&'a FieldArg<'doc>);
method to_tokens (line 1922) | fn to_tokens(&self, tokens: &mut TokenStream) {
type FieldArgsToTokensInterface (line 1943) | struct FieldArgsToTokensInterface<'a, 'doc>(&'a FieldArg<'doc>);
method to_tokens (line 1946) | fn to_tokens(&self, tokens: &mut TokenStream) {
type Subscription (line 1962) | struct Subscription<'doc> {
method to_tokens (line 1970) | fn to_tokens(&self, tokens: &mut TokenStream) {
type Interface (line 2020) | struct Interface<'doc> {
method to_tokens (line 2030) | fn to_tokens(&self, tokens: &mut TokenStream) {
type Union (line 2085) | struct Union<'doc> {
method to_tokens (line 2093) | fn to_tokens(&self, tokens: &mut TokenStream) {
type UnionVariant (line 2137) | struct UnionVariant {
method to_tokens (line 2144) | fn to_tokens(&self, tokens: &mut TokenStream) {
type Enum (line 2158) | struct Enum<'doc> {
method to_tokens (line 2165) | fn to_tokens(&self, tokens: &mut TokenStream) {
type EnumVariant (line 2232) | struct EnumVariant<'doc> {
method to_tokens (line 2240) | fn to_tokens(&self, tokens: &mut TokenStream) {
type InputObject (line 2272) | struct InputObject<'doc> {
method to_tokens (line 2279) | fn to_tokens(&self, tokens: &mut TokenStream) {
type InputObjectField (line 2371) | struct InputObjectField<'doc> {
method to_tokens (line 2378) | fn to_tokens(&self, tokens: &mut TokenStream) {
type SchemaType (line 2398) | struct SchemaType {
method to_tokens (line 2405) | fn to_tokens(&self, tokens: &mut TokenStream) {
function add_deprecation_graphql_attr_token (line 2424) | fn add_deprecation_graphql_attr_token(
type GraphqlAttr (line 2438) | enum GraphqlAttr {
method new (line 2453) | fn new() -> Self {
method new_object (line 2457) | fn new_object() -> Self {
method new_subscription (line 2461) | fn new_subscription() -> Self {
method new_interface_top_level (line 2465) | fn new_interface_top_level() -> Self {
method push (line 2469) | fn push(&mut self, key: Ident) {
method push_key_value (line 2479) | fn push_key_value<T: ToTokens>(&mut self, key: Ident, value: T) {
method push_fn (line 2492) | fn push_fn<T, I>(&mut self, name: Ident, values: I)
type GraphqlAttrItem (line 2446) | enum GraphqlAttrItem {
method to_tokens (line 2513) | fn to_tokens(&self, tokens: &mut TokenStream) {
method to_tokens (line 2536) | fn to_tokens(&self, tokens: &mut TokenStream) {
type FieldLocation (line 2547) | enum FieldLocation {
function maybe_wrap_final_return_type_in_result (line 2553) | fn maybe_wrap_final_return_type_in_result(
FILE: juniper-from-schema-code-gen/src/ast_pass/directive_parsing.rs
type FromDirective (line 9) | pub trait FromDirective: Sized {
method from_directive (line 10) | fn from_directive<'doc>(dir: &'doc Directive<'doc, &'doc str>) -> Resu...
method from_directive (line 51) | fn from_directive<'doc>(dir: &'doc Directive<'doc, &'doc str>) -> Resu...
type FromDirectiveArguments (line 13) | pub trait FromDirectiveArguments: Sized + Default {
constant KEY (line 14) | const KEY: &'static str;
method from_directive_args (line 16) | fn from_directive_args<'doc>(
constant KEY (line 22) | const KEY: &'static str = T::KEY;
method from_directive_args (line 24) | fn from_directive_args<'doc>(
constant KEY (line 203) | const KEY: &'static str = "ownership";
method from_directive_args (line 205) | fn from_directive_args<'doc>(
constant KEY (line 246) | const KEY: &'static str = "infallible";
method from_directive_args (line 248) | fn from_directive_args<'doc>(
constant KEY (line 270) | const KEY: &'static str = "async";
method from_directive_args (line 272) | fn from_directive_args<'doc>(
constant KEY (line 300) | const KEY: &'static str = "stream_type";
method from_directive_args (line 302) | fn from_directive_args<'doc>(
constant KEY (line 326) | const KEY: &'static str = "stream_item_infallible";
method from_directive_args (line 328) | fn from_directive_args<'doc>(
constant KEY (line 358) | const KEY: &'static str = "with_time_zone";
method from_directive_args (line 360) | fn from_directive_args<'doc>(
type Deprecation (line 39) | pub enum Deprecation {
method default (line 45) | fn default() -> Self {
type JuniperDirective (line 98) | pub struct JuniperDirective<T> {
method default (line 104) | fn default() -> Self {
type FieldDirectives (line 174) | pub struct FieldDirectives {
type Ownership (line 184) | pub enum Ownership {
method is_as_ref (line 191) | pub fn is_as_ref(&self) -> bool {
method default (line 197) | fn default() -> Self {
type Infallible (line 235) | pub struct Infallible {
method default (line 240) | fn default() -> Self {
type Async (line 265) | pub struct Async {
method default (line 289) | fn default() -> Self {
type StreamType (line 295) | pub struct StreamType {
type StreamItemInfallible (line 321) | pub struct StreamItemInfallible {
type DateTimeScalarArguments (line 345) | pub struct DateTimeScalarArguments {
method default (line 350) | fn default() -> Self {
function value_as_string (line 376) | fn value_as_string<'doc>(value: &'doc Value<'doc, &'doc str>) -> Result<...
function value_as_bool (line 388) | fn value_as_bool<'doc>(value: &'doc Value<'doc, &'doc str>) -> Result<bo...
type ParseDirective (line 400) | pub trait ParseDirective<T> {
method parse_directives (line 403) | fn parse_directives(&mut self, input: T) -> Self::Output;
type Output (line 407) | type Output = FieldDirectives;
function parse_directives (line 409) | fn parse_directives(&mut self, input: &'doc Field<'doc, &'doc str>) -> S...
type Output (line 459) | type Output = Deprecation;
function parse_directives (line 461) | fn parse_directives(&mut self, input: &'doc EnumValue<'doc, &'doc str>) ...
type DateTimeScalarType (line 480) | pub struct DateTimeScalarType<'a>(pub &'a ScalarType<'a, &'a str>);
type Output (line 486) | type Output = DateTimeScalarArguments;
method parse_directives (line 488) | fn parse_directives(&mut self, input: DateTimeScalarType<'doc>) -> Self:...
FILE: juniper-from-schema-code-gen/src/ast_pass/error.rs
type Error (line 6) | pub struct Error {
method display (line 12) | pub fn display<'a>(&'a self, raw_schema: &'a str) -> ErrorDisplay<'a> {
type ErrorDisplay (line 21) | pub struct ErrorDisplay<'a> {
function fmt (line 27) | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
type Deprecation (line 73) | pub enum Deprecation {
method fmt (line 80) | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
type ValueType (line 93) | pub enum ValueType {
method from (line 106) | fn from(value: &'doc Value<'doc, &'doc str>) -> Self {
method fmt (line 122) | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
type Ownership (line 139) | pub enum Ownership {
method fmt (line 144) | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
type Juniper (line 156) | pub enum Juniper {
method fmt (line 161) | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
type UnsupportedDirectiveKind (line 169) | pub enum UnsupportedDirectiveKind {
method fmt (line 180) | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
type ErrorKind (line 194) | pub enum ErrorKind {
method description (line 230) | fn description(&self) -> String {
method notes (line 303) | fn notes(&self) -> Option<String> {
type Indent (line 380) | trait Indent {
method indent (line 381) | fn indent(&self, size: usize) -> String;
method indent (line 385) | fn indent(&self, size: usize) -> String {
function number_of_digits (line 399) | fn number_of_digits(n: i32) -> usize {
function test_number_of_digits (line 413) | fn test_number_of_digits() {
FILE: juniper-from-schema-code-gen/src/ast_pass/mod.rs
function type_name (line 15) | pub fn type_name<'doc>(type_: &Type<'doc, &'doc str>) -> &'doc str {
type TypeKind (line 24) | pub enum TypeKind {
type EmitError (line 29) | pub trait EmitError {
method emit_error (line 30) | fn emit_error(&mut self, pos: Pos, kind: ErrorKind);
method emit_error (line 34) | fn emit_error(&mut self, pos: Pos, kind: ErrorKind) {
method emit_error (line 223) | fn emit_error(&mut self, pos: Pos, kind: ErrorKind) {
type AstData (line 41) | pub struct AstData<'doc> {
function visit_object_type (line 53) | fn visit_object_type(&mut self, obj: &'doc ObjectType<'doc, &'doc str>) {
function visit_scalar_type (line 62) | fn visit_scalar_type(&mut self, scalar: &'doc ScalarType<'doc, &'doc str...
function visit_enum_type (line 79) | fn visit_enum_type(&mut self, enum_type: &'doc EnumType<'doc, &'doc str>) {
function visit_union_type (line 83) | fn visit_union_type(&mut self, union_type: &'doc UnionType<'doc, &'doc s...
function visit_input_object_type (line 87) | fn visit_input_object_type(&mut self, input_type: &'doc InputObjectType<...
function visit_schema_definition (line 96) | fn visit_schema_definition(&mut self, node: &'doc SchemaDefinition<'doc,...
function new_from_doc (line 104) | pub fn new_from_doc(doc: &'doc Document<'doc, &'doc str>) -> Result<Self...
function new (line 115) | fn new() -> Self {
function get_implementors_of_interface (line 128) | pub fn get_implementors_of_interface(&self, name: &str) -> Option<&Vec<&...
function date_scalar_defined (line 132) | pub fn date_scalar_defined(&self) -> bool {
function date_time_scalar_defined (line 136) | pub fn date_time_scalar_defined(&self) -> bool {
function date_time_scalar_definition (line 140) | pub fn date_time_scalar_definition(&self) -> Option<DateTimeScalarDefini...
function uuid_scalar_defined (line 152) | pub fn uuid_scalar_defined(&self) -> bool {
function url_scalar_defined (line 156) | pub fn url_scalar_defined(&self) -> bool {
function is_scalar (line 160) | pub fn is_scalar(&self, name: &str) -> bool {
function is_enum_type (line 164) | pub fn is_enum_type(&self, name: &str) -> bool {
function is_union_type (line 168) | pub fn is_union_type(&self, name: &str) -> bool {
function is_interface_type (line 172) | pub fn is_interface_type(&self, name: &str) -> bool {
function input_object_field_is_nullable (line 177) | pub fn input_object_field_is_nullable(
function input_object_field_names (line 193) | pub fn input_object_field_names(
function input_object_field_type_name (line 205) | pub fn input_object_field_type_name(
function is_subscription_type (line 215) | pub fn is_subscription_type(&self, name: &'doc str) -> bool {
type DateTimeScalarDefinition (line 229) | pub enum DateTimeScalarDefinition {
type NullableType (line 235) | pub enum NullableType<'a> {
function from_schema_type (line 242) | pub fn from_schema_type(ty: &Type<'a, &'a str>) -> Self {
function debug_print (line 249) | fn debug_print(&self) -> String {
function map (line 258) | fn map<'a>(ty: &Type<'a, &'a str>) -> NullableType<'a> {
function map_inner (line 270) | fn map_inner<'a>(ty: &Type<'a, &'a str>, inside_non_null: bool) -> Nulla...
function named_type (line 297) | fn named_type() {
FILE: juniper-from-schema-code-gen/src/ast_pass/schema_visitor.rs
type SchemaVisitor (line 8) | pub trait SchemaVisitor<'doc> {
method visit_document (line 10) | fn visit_document(&mut self, _: &'doc schema::Document<'doc, &'doc str...
method visit_schema_definition (line 13) | fn visit_schema_definition(&mut self, _: &'doc schema::SchemaDefinitio...
method visit_directive_definition (line 16) | fn visit_directive_definition(
method visit_type_definition (line 23) | fn visit_type_definition(&mut self, _: &'doc schema::TypeDefinition<'d...
method visit_scalar_type (line 26) | fn visit_scalar_type(&mut self, _: &'doc schema::ScalarType<'doc, &'do...
method visit_object_type (line 29) | fn visit_object_type(&mut self, _: &'doc schema::ObjectType<'doc, &'do...
method visit_interface_type (line 32) | fn visit_interface_type(&mut self, _: &'doc schema::InterfaceType<'doc...
method visit_union_type (line 35) | fn visit_union_type(&mut self, _: &'doc schema::UnionType<'doc, &'doc ...
method visit_enum_type (line 38) | fn visit_enum_type(&mut self, _: &'doc schema::EnumType<'doc, &'doc st...
method visit_input_object_type (line 41) | fn visit_input_object_type(&mut self, _: &'doc schema::InputObjectType...
method visit_type_extension (line 44) | fn visit_type_extension(&mut self, _: &'doc schema::TypeExtension<'doc...
method visit_scalar_type_extension (line 47) | fn visit_scalar_type_extension(
method visit_object_type_extension (line 54) | fn visit_object_type_extension(
method visit_interface_type_extension (line 61) | fn visit_interface_type_extension(
method visit_union_type_extension (line 68) | fn visit_union_type_extension(&mut self, _: &'doc schema::UnionTypeExt...
method visit_enum_type_extension (line 72) | fn visit_enum_type_extension(&mut self, _: &'doc schema::EnumTypeExten...
method visit_input_object_type_extension (line 75) | fn visit_input_object_type_extension(
method and (line 82) | fn and<T>(self, rhs: T) -> And<Self, T>
function visit_document (line 90) | pub fn visit_document<'doc, V: SchemaVisitor<'doc>>(
function visit_schema_definition (line 106) | pub fn visit_schema_definition<'doc, V: SchemaVisitor<'doc>>(
function visit_directive_definition (line 113) | pub fn visit_directive_definition<'doc, V: SchemaVisitor<'doc>>(
function visit_type_definition (line 120) | pub fn visit_type_definition<'doc, V: SchemaVisitor<'doc>>(
function visit_scalar_type (line 135) | pub fn visit_scalar_type<'doc, V: SchemaVisitor<'doc>>(
function visit_object_type (line 142) | pub fn visit_object_type<'doc, V: SchemaVisitor<'doc>>(
function visit_interface_type (line 149) | pub fn visit_interface_type<'doc, V: SchemaVisitor<'doc>>(
function visit_union_type (line 156) | pub fn visit_union_type<'doc, V: SchemaVisitor<'doc>>(
function visit_enum_type (line 163) | pub fn visit_enum_type<'doc, V: SchemaVisitor<'doc>>(
function visit_input_object_type (line 170) | pub fn visit_input_object_type<'doc, V: SchemaVisitor<'doc>>(
function visit_type_extension (line 177) | pub fn visit_type_extension<'doc, V: SchemaVisitor<'doc>>(
function visit_scalar_type_extension (line 192) | pub fn visit_scalar_type_extension<'doc, V: SchemaVisitor<'doc>>(
function visit_object_type_extension (line 199) | pub fn visit_object_type_extension<'doc, V: SchemaVisitor<'doc>>(
function visit_interface_type_extension (line 206) | pub fn visit_interface_type_extension<'doc, V: SchemaVisitor<'doc>>(
function visit_union_type_extension (line 213) | pub fn visit_union_type_extension<'doc, V: SchemaVisitor<'doc>>(
function visit_enum_type_extension (line 220) | pub fn visit_enum_type_extension<'doc, V: SchemaVisitor<'doc>>(
function visit_input_object_type_extension (line 227) | pub fn visit_input_object_type_extension<'doc, V: SchemaVisitor<'doc>>(
type And (line 235) | pub struct And<A, B> {
function into_inner (line 241) | pub fn into_inner(self) -> (A, B) {
function visit_document (line 252) | fn visit_document(&mut self, node: &'doc schema::Document<'doc, &'doc st...
function visit_schema_definition (line 258) | fn visit_schema_definition(&mut self, node: &'doc schema::SchemaDefiniti...
function visit_directive_definition (line 264) | fn visit_directive_definition(
function visit_type_definition (line 273) | fn visit_type_definition(&mut self, node: &'doc schema::TypeDefinition<'...
function visit_scalar_type (line 279) | fn visit_scalar_type(&mut self, node: &'doc schema::ScalarType<'doc, &'d...
function visit_object_type (line 285) | fn visit_object_type(&mut self, node: &'doc schema::ObjectType<'doc, &'d...
function visit_interface_type (line 291) | fn visit_interface_type(&mut self, node: &'doc schema::InterfaceType<'do...
function visit_union_type (line 297) | fn visit_union_type(&mut self, node: &'doc schema::UnionType<'doc, &'doc...
function visit_enum_type (line 303) | fn visit_enum_type(&mut self, node: &'doc schema::EnumType<'doc, &'doc s...
function visit_input_object_type (line 309) | fn visit_input_object_type(&mut self, node: &'doc schema::InputObjectTyp...
function visit_type_extension (line 315) | fn visit_type_extension(&mut self, node: &'doc schema::TypeExtension<'do...
function visit_scalar_type_extension (line 321) | fn visit_scalar_type_extension(
function visit_object_type_extension (line 330) | fn visit_object_type_extension(
function visit_interface_type_extension (line 339) | fn visit_interface_type_extension(
function visit_union_type_extension (line 348) | fn visit_union_type_extension(
function visit_enum_type_extension (line 357) | fn visit_enum_type_extension(
function visit_input_object_type_extension (line 366) | fn visit_input_object_type_extension(
FILE: juniper-from-schema-code-gen/src/ast_pass/validations.rs
type FieldNameCaseValidator (line 10) | pub struct FieldNameCaseValidator {
method new (line 15) | pub fn new() -> Self {
method visit_object_type (line 23) | fn visit_object_type(&mut self, ty: &'doc schema::ObjectType<'doc, &'d...
method visit_interface_type (line 27) | fn visit_interface_type(&mut self, ty: &'doc schema::InterfaceType<'do...
method visit_input_object_type (line 31) | fn visit_input_object_type(&mut self, ty: &'doc schema::InputObjectTyp...
method validate_fields (line 39) | fn validate_fields<'doc>(&mut self, fields: &'doc [Field<'doc, &'doc s...
method validate_field (line 45) | fn validate_field(&mut self, name: &str, pos: Pos) {
type UuidNameCaseValidator (line 52) | pub struct UuidNameCaseValidator {
method new (line 57) | pub fn new() -> Self {
method visit_scalar_type (line 65) | fn visit_scalar_type(&mut self, scalar: &'doc ScalarType<'doc, &'doc s...
function is_snake_case (line 73) | fn is_snake_case(s: &str) -> bool {
function test_is_snake_case (line 83) | fn test_is_snake_case() {
FILE: juniper-from-schema-code-gen/src/lib.rs
constant DATE_TIME_SCALAR_NAME (line 25) | const DATE_TIME_SCALAR_NAME: &str = "DateTimeUtc";
constant DATE_SCALAR_NAME (line 26) | const DATE_SCALAR_NAME: &str = "Date";
constant UUID_SCALAR_NAME (line 27) | const UUID_SCALAR_NAME: &str = "Uuid";
constant URL_SCALAR_NAME (line 28) | const URL_SCALAR_NAME: &str = "Url";
type CodeGen (line 31) | pub struct CodeGen {
method build_from_schema_file (line 38) | pub fn build_from_schema_file(path: PathBuf) -> CodeGenBuilder {
method build_from_schema_literal (line 46) | pub fn build_from_schema_literal(schema: String) -> CodeGenBuilder {
method generate_code (line 54) | pub fn generate_code(self) -> Result<proc_macro2::TokenStream, Error> {
function include_literal_schema (line 106) | fn include_literal_schema(tokens: &mut proc_macro2::TokenStream, schema_...
type Error (line 120) | pub enum Error {
method fmt (line 130) | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
type CodeGenBuilder (line 161) | pub struct CodeGenBuilder {
method context_type (line 168) | pub fn context_type(mut self, context_type: syn::Type) -> Self {
method error_type (line 173) | pub fn error_type(mut self, error_type: syn::Type) -> Self {
method finish (line 178) | pub fn finish(self) -> CodeGen {
type SchemaLocation (line 188) | enum SchemaLocation {
function default_error_type (line 193) | pub fn default_error_type() -> syn::Type {
function default_context_type (line 197) | pub fn default_context_type() -> syn::Type {
function debugging_enabled (line 201) | fn debugging_enabled() -> bool {
FILE: juniper-from-schema-proc-macro/src/lib.rs
function graphql_schema_from_file (line 22) | pub fn graphql_schema_from_file(input: proc_macro::TokenStream) -> proc_...
function graphql_schema (line 79) | pub fn graphql_schema(input: proc_macro::TokenStream) -> proc_macro::Tok...
FILE: juniper-from-schema-proc-macro/src/parse_input.rs
type GraphqlSchemaFromFileInput (line 9) | pub struct GraphqlSchemaFromFileInput {
method parse (line 16) | fn parse(input: ParseStream) -> syn::Result<Self> {
FILE: juniper-from-schema-proc-macro/tests/version-numbers.rs
function test_html_root_url (line 5) | fn test_html_root_url() {
FILE: juniper-from-schema/examples/async.rs
type Context (line 22) | pub struct Context;
type Tweet (line 26) | pub struct Tweet {
method field_id (line 32) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
method field_text (line 36) | fn field_text(&self, executor: &Executor<Context>) -> FieldResult<&Strin...
type Query (line 41) | pub struct Query;
method field_find_tweet (line 45) | async fn field_find_tweet<'s, 'r, 'a>(
function main (line 60) | fn main() {}
FILE: juniper-from-schema/examples/default_argument_values.rs
type Context (line 25) | pub struct Context;
type Post (line 29) | pub struct Post {
method field_id (line 34) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
type Query (line 39) | pub struct Query;
method field_all_posts (line 42) | fn field_all_posts(
function main (line 57) | fn main() {}
FILE: juniper-from-schema/examples/enumeration_types.rs
function main (line 25) | fn main() {}
type Context (line 27) | pub struct Context;
type Post (line 31) | pub struct Post {
method field_id (line 36) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
type Query (line 41) | pub struct Query;
method field_all_posts (line 44) | fn field_all_posts(
FILE: juniper-from-schema/examples/hello_world.rs
type Context (line 24) | pub struct Context;
type Query (line 27) | pub struct Query;
method field_hello_world (line 30) | fn field_hello_world(&self, executor: &Executor<Context>, name: String) ...
type Mutation (line 35) | pub struct Mutation;
method field_noop (line 38) | fn field_noop(&self, executor: &Executor<Context>) -> FieldResult<&bool> {
function main (line 43) | fn main() {
FILE: juniper-from-schema/examples/input_types.rs
function main (line 28) | fn main() {}
type Context (line 30) | pub struct Context;
type Post (line 34) | pub struct Post {
method field_id (line 39) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
method field_title (line 43) | fn field_title(&self, executor: &Executor<Context>) -> FieldResult<&Stri...
type Query (line 48) | pub struct Query;
method field_noop (line 51) | fn field_noop(&self, executor: &Executor<Context>) -> FieldResult<&bool> {
type Mutation (line 56) | pub struct Mutation;
method field_create_post (line 59) | fn field_create_post(
FILE: juniper-from-schema/examples/interface.rs
type Context (line 31) | pub struct Context;
type Article (line 35) | pub struct Article {
method field_id (line 41) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
method field_text (line 45) | fn field_text(&self, executor: &Executor<Context>) -> FieldResult<&Strin...
type Tweet (line 50) | pub struct Tweet {
method field_id (line 56) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
method field_text (line 60) | fn field_text(&self, executor: &Executor<Context>) -> FieldResult<&Strin...
type Query (line 65) | pub struct Query;
method field_search (line 68) | fn field_search(
function main (line 89) | fn main() {}
FILE: juniper-from-schema/examples/query_trails.rs
function main (line 7) | fn main() {}
type Context (line 9) | pub struct Context;
type Query (line 32) | pub struct Query;
method field_all_posts (line 35) | fn field_all_posts(
type Post (line 56) | pub struct Post {
method field_id (line 62) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
method field_author (line 66) | fn field_author(
type User (line 75) | pub struct User {
method field_id (line 80) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
FILE: juniper-from-schema/examples/subscription.rs
type Context (line 30) | pub struct Context {
type Tweet (line 37) | pub struct Tweet {
method field_id (line 43) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
type Subscription (line 48) | pub struct Subscription;
method field_tweets (line 51) | fn field_tweets(
type Query (line 63) | pub struct Query;
method field_ping (line 67) | fn field_ping(&self, executor: &Executor<Context>) -> FieldResult<&bool> {
function main (line 72) | fn main() {}
FILE: juniper-from-schema/examples/union_types.rs
type Context (line 28) | pub struct Context;
type Article (line 32) | pub struct Article {
method field_id (line 38) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
method field_text (line 42) | fn field_text(&self, executor: &Executor<Context>) -> FieldResult<&Strin...
type Tweet (line 47) | pub struct Tweet {
method field_id (line 53) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&ID> {
method field_text (line 57) | fn field_text(&self, executor: &Executor<Context>) -> FieldResult<&Strin...
type Query (line 62) | pub struct Query;
method field_search (line 65) | fn field_search(
function main (line 86) | fn main() {}
FILE: juniper-from-schema/src/lib.rs
type Walked (line 1761) | pub struct Walked;
type NotWalked (line 1764) | pub struct NotWalked;
type QueryTrail (line 1767) | pub struct QueryTrail<'r, T, K> {
function walk (line 1780) | pub fn walk(self) -> Option<QueryTrail<'r, T, Walked>> {
function new (line 1798) | pub fn new(lh: &'r LookAheadSelection<'r, DefaultScalarValue>) -> QueryT...
function test_compile_pass (line 1831) | fn test_compile_pass() {
function setup_subscription_tests (line 1842) | fn setup_subscription_tests(outcome: &str, t: &TestCases) {
FILE: juniper-from-schema/tests/compile_fail/docs_on_special_case_scalars.rs
type Query (line 28) | pub struct Query;
method field_foo (line 31) | fn field_foo(&self, _: &Executor<Context>) -> FieldResult<String> {
FILE: juniper-from-schema/tests/compile_fail/invalid_as_ref_type.rs
type Query (line 14) | pub struct Query;
method field_as_ref_string (line 17) | fn field_as_ref_string(
FILE: juniper-from-schema/tests/compile_fail/invalid_date_time_scalar_directive.rs
type Query (line 18) | pub struct Query;
method field_date_time (line 21) | fn field_date_time(&self, _: &Executor<Context>) -> FieldResult<NaiveDat...
FILE: juniper-from-schema/tests/compile_fail/invalid_juniper_directive_definition.rs
type Query (line 22) | pub struct Query;
method field_string (line 25) | fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&Str...
FILE: juniper-from-schema/tests/compile_fail/invalid_stream_return_type.rs
type Query (line 24) | pub struct Query;
method field_ping (line 27) | fn field_ping(&self, _: &Executor<Context>) -> FieldResult<&bool> {
type Subscription (line 32) | pub struct Subscription;
method field_users (line 35) | fn field_users<'r, 'a>(
type User (line 44) | pub struct User {
method field_id (line 50) | fn field_id(&self, _: &Executor<Context>) -> FieldResult<&ID> {
method field_name (line 54) | fn field_name(&self, _: &Executor<Context>) -> FieldResult<&String> {
FILE: juniper-from-schema/tests/compile_fail/scalar_with_built_in_name.rs
type Query (line 18) | pub struct Query;
method field_hello_world (line 21) | fn field_hello_world(&self, executor: &Executor<Context>, name: String) ...
FILE: juniper-from-schema/tests/compile_fail/snake_cased_fields_on_input_object_types.rs
type Query (line 16) | pub struct Query;
method field_field (line 19) | fn field_field(&self, _: &Executor<Context>) -> FieldResult<&String> {
FILE: juniper-from-schema/tests/compile_fail/snake_cased_fields_on_interfaces.rs
type Query (line 16) | pub struct Query;
method field_field (line 19) | fn field_field(
FILE: juniper-from-schema/tests/compile_fail/snake_cased_fields_on_types.rs
type Query (line 12) | pub struct Query;
method field_snake_cased (line 15) | fn field_snake_cased(&self, executor: &Executor<Context>) -> FieldResult...
FILE: juniper-from-schema/tests/compile_fail/unknown_directive.rs
type Query (line 12) | pub struct Query;
method field_string (line 15) | fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&Str...
FILE: juniper-from-schema/tests/compile_fail/unsupported_config.rs
type Query (line 9) | pub struct Query;
method field_foo (line 12) | fn field_foo(&self, _: &Executor<Context>) -> FieldResult<&String> {
FILE: juniper-from-schema/tests/compile_fail/uppercase_uuid.rs
type Query (line 18) | pub struct Query;
method field_uuid (line 21) | fn field_uuid(&self, _: &Executor<Context>) -> FieldResult<Uuid> {
FILE: juniper-from-schema/tests/compile_pass/async.rs
type Query (line 32) | pub struct Query;
method field_async_ping (line 36) | async fn field_async_ping<'s, 'r, 'a>(&'s self, _: &Executor<'r, 'a, Con...
method field_sync_ping (line 40) | fn field_sync_ping(&self, _: &Executor<Context>) -> bool {
type User (line 45) | pub struct User;
method field_id (line 49) | async fn field_id<'s, 'r, 'a>(&'s self, _: &Executor<'r, 'a, Context>) -...
type Ready (line 55) | pub struct Ready<T>(Option<T>);
type Output (line 60) | type Output = T;
method poll (line 62) | fn poll(mut self: Pin<&mut Self>, _cx: &mut std::task::Context<'_>) -> P...
function ready (line 67) | pub fn ready<T>(t: T) -> Ready<T> {
FILE: juniper-from-schema/tests/compile_pass/async_as_ref.rs
type Query (line 18) | pub struct Query;
method field_find (line 22) | async fn field_find<'s, 'r, 'a>(
type User (line 33) | pub struct User {
method field_id (line 38) | fn field_id(&self, _: &Executor<Context>) -> &ID {
FILE: juniper-from-schema/tests/compile_pass/async_field_returning_type.rs
type Query (line 21) | pub struct Query;
method field_find (line 25) | async fn field_find<'s, 'r, 'a>(
type User (line 36) | pub struct User {
method field_id (line 41) | fn field_id(&self, _: &Executor<Context>) -> &ID {
FILE: juniper-from-schema/tests/compile_pass/async_returning_reference.rs
type Query (line 21) | pub struct Query;
method field_find (line 25) | async fn field_find<'s, 'r, 'a>(
type User (line 36) | pub struct User {
method field_id (line 41) | fn field_id(&self, _: &Executor<Context>) -> &ID {
FILE: juniper-from-schema/tests/compile_pass/correct_executor_signature.rs
type Query (line 12) | pub struct Query;
method field_field (line 15) | fn field_field(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
FILE: juniper-from-schema/tests/compile_pass/custom_scalar.rs
type Query (line 14) | pub struct Query;
method field_field (line 17) | fn field_field<'a>(
FILE: juniper-from-schema/tests/compile_pass/customizing_context_name.rs
type MyContext (line 9) | pub struct MyContext;
type Query (line 12) | pub struct Query;
method field_foo (line 15) | fn field_foo(&self, _: &Executor<MyContext>) -> FieldResult<&String> {
FILE: juniper-from-schema/tests/compile_pass/customizing_the_error_type.rs
type MyError (line 9) | pub enum MyError {
method into_field_error (line 15) | fn into_field_error(self) -> juniper::FieldError {
type Query (line 20) | pub struct Query;
method field_string (line 23) | fn field_string(&self, executor: &Executor<Context>) -> Result<&String, ...
FILE: juniper-from-schema/tests/compile_pass/dates_and_times.rs
type Query (line 20) | pub struct Query;
method field_date (line 23) | fn field_date(&self, _: &Executor<Context>) -> FieldResult<NaiveDate> {
method field_date_time (line 27) | fn field_date_time(&self, _: &Executor<Context>) -> FieldResult<DateTime...
FILE: juniper-from-schema/tests/compile_pass/directive_definitions_are_allowed.rs
type Query (line 14) | pub struct Query;
method field_string (line 17) | fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&Str...
FILE: juniper-from-schema/tests/compile_pass/empty_mutations.rs
type Query (line 12) | pub struct Query;
method field_string (line 15) | fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&Str...
function this_should_compile (line 20) | fn this_should_compile() {
FILE: juniper-from-schema/tests/compile_pass/enums.rs
type Query (line 18) | pub struct Query;
method field_yes_no (line 21) | fn field_yes_no(
FILE: juniper-from-schema/tests/compile_pass/field_args.rs
type Query (line 13) | pub struct Query;
method field_single (line 16) | fn field_single(&self, executor: &Executor<Context>, arg: i32) -> FieldR...
method field_multiple (line 20) | fn field_multiple(
FILE: juniper-from-schema/tests/compile_pass/infallible_directive.rs
type Query (line 24) | pub struct Query;
method field_unowned (line 27) | fn field_unowned(&self, _: &Executor<Context>) -> &String {
method field_owned (line 31) | fn field_owned(&self, _: &Executor<Context>) -> String {
method field_owned_reordered (line 35) | fn field_owned_reordered(&self, _: &Executor<Context>) -> String {
type User (line 40) | pub struct User;
method field_id (line 43) | fn field_id(&self, _: &Executor<Context>) -> &ID {
FILE: juniper-from-schema/tests/compile_pass/input_object.rs
type Query (line 17) | pub struct Query;
method field_users_at_location (line 20) | fn field_users_at_location(
FILE: juniper-from-schema/tests/compile_pass/input_object_clone.rs
type Query (line 17) | pub struct Query;
method field_users_at_location (line 20) | fn field_users_at_location(
FILE: juniper-from-schema/tests/compile_pass/input_objects_have_public_fields.rs
type Query (line 21) | pub struct Query;
method field_users_at_location (line 24) | fn field_users_at_location(
FILE: juniper-from-schema/tests/compile_pass/naive_date_time.rs
type Query (line 18) | pub struct Query;
method field_date_time (line 21) | fn field_date_time(&self, _: &Executor<Context>) -> FieldResult<NaiveDat...
FILE: juniper-from-schema/tests/compile_pass/non_null_list_non_null_items.rs
type Query (line 12) | pub struct Query;
method field_field (line 15) | fn field_field(&self, executor: &Executor<Context>) -> FieldResult<&Vec<...
FILE: juniper-from-schema/tests/compile_pass/non_null_list_nullable_items.rs
type Query (line 12) | pub struct Query;
method field_field (line 15) | fn field_field(&self, executor: &Executor<Context>) -> FieldResult<&Vec<...
FILE: juniper-from-schema/tests/compile_pass/nullable_list_non_null_items.rs
type Query (line 12) | pub struct Query;
method field_field (line 15) | fn field_field(&self, executor: &Executor<Context>) -> FieldResult<&Opti...
FILE: juniper-from-schema/tests/compile_pass/nullable_list_nullable_items.rs
type Query (line 12) | pub struct Query;
method field_field (line 15) | fn field_field(
FILE: juniper-from-schema/tests/compile_pass/ownership_attributes.rs
type Query (line 16) | pub struct Query;
method field_borrowed_string (line 19) | fn field_borrowed_string(&self, executor: &Executor<Context>) -> FieldRe...
method field_owned_string (line 23) | fn field_owned_string(&self, executor: &Executor<Context>) -> FieldResul...
method field_as_ref_string (line 27) | fn field_as_ref_string<'s>(
FILE: juniper-from-schema/tests/compile_pass/query_trail.rs
type Query (line 22) | pub struct Query;
method field_user (line 25) | fn field_user(
type User (line 38) | pub struct User {
method field_id (line 43) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
method field_club (line 47) | fn field_club(
method field_club2 (line 55) | fn field_club2(
type Club (line 64) | pub struct Club {
method field_id (line 69) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
FILE: juniper-from-schema/tests/compile_pass/query_trail_methods_for_interfaces.rs
type Query (line 37) | pub struct Query;
method field_posts (line 40) | fn field_posts(
type Post (line 49) | pub struct Post {
method field_comments (line 54) | fn field_comments(
type Comment (line 63) | pub struct Comment {
method field_id (line 68) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
method field_author (line 72) | fn field_author(
type User (line 89) | pub struct User {
method field_id (line 94) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
method field_country (line 98) | fn field_country(
type Country (line 107) | pub struct Country {
method field_id (line 112) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
FILE: juniper-from-schema/tests/compile_pass/query_trail_methods_for_union_types.rs
type Query (line 40) | pub struct Query;
method field_posts (line 43) | fn field_posts(
type Post (line 52) | pub struct Post {
method field_comments (line 57) | fn field_comments(
type Comment (line 66) | pub struct Comment {
method field_id (line 71) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
method field_author (line 75) | fn field_author(
type User (line 91) | pub struct User {
method field_id (line 96) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
method field_country (line 100) | fn field_country(
type Company (line 109) | pub struct Company {
method field_id (line 114) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
method field_name (line 118) | fn field_name(&self, executor: &Executor<Context>) -> FieldResult<String> {
method field_country_of_operation (line 122) | fn field_country_of_operation(
type Country (line 131) | pub struct Country {
method field_id (line 136) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
FILE: juniper-from-schema/tests/compile_pass/returning_references.rs
type Query (line 8) | pub struct Query;
method field_user_nullable (line 11) | fn field_user_nullable(
method field_user_non_null (line 20) | fn field_user_non_null(
type User (line 30) | pub struct User {
method field_id (line 37) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
method field_name_nullable (line 41) | fn field_name_nullable(
method field_name_non_null (line 48) | fn field_name_non_null(&self, executor: &Executor<Context>) -> FieldResu...
function find_user (line 53) | fn find_user(id: i32) -> Option<User> {
FILE: juniper-from-schema/tests/compile_pass/setup.rs
type Context (line 4) | pub struct Context;
function main (line 7) | fn main() {}
function __use_all_the_imports (line 10) | fn __use_all_the_imports(
FILE: juniper-from-schema/tests/compile_pass/simple_non_null_scalars.rs
type Query (line 15) | pub struct Query;
method field_string (line 18) | fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&Str...
method field_float (line 22) | fn field_float(&self, executor: &Executor<Context>) -> FieldResult<&f64> {
method field_int (line 26) | fn field_int(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
method field_boolean (line 30) | fn field_boolean(&self, executor: &Executor<Context>) -> FieldResult<&bo...
FILE: juniper-from-schema/tests/compile_pass/simple_nullable_scalars.rs
type Query (line 15) | pub struct Query;
method field_string (line 18) | fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&Opt...
method field_float (line 22) | fn field_float(&self, executor: &Executor<Context>) -> FieldResult<&Opti...
method field_int (line 26) | fn field_int(&self, executor: &Executor<Context>) -> FieldResult<&Option...
method field_boolean (line 30) | fn field_boolean(&self, executor: &Executor<Context>) -> FieldResult<&Op...
FILE: juniper-from-schema/tests/compile_pass/url.rs
type Query (line 18) | pub struct Query;
method field_url (line 21) | fn field_url(&self, _: &Executor<Context>) -> FieldResult<Url> {
FILE: juniper-from-schema/tests/compile_pass/uuid.rs
type Query (line 18) | pub struct Query;
method field_uuid (line 21) | fn field_uuid(&self, _: &Executor<Context>) -> FieldResult<Uuid> {
FILE: juniper-from-schema/tests/compile_pass/valid_juniper_directive_definition.rs
type Query (line 21) | pub struct Query;
method field_string (line 24) | fn field_string(&self, executor: &Executor<Context>) -> FieldResult<&Str...
FILE: juniper-from-schema/tests/converting_query_trails_test.rs
type Context (line 5) | pub struct Context;
type Query (line 31) | pub struct Query;
method field_entities (line 34) | fn field_entities(
method field_search (line 45) | fn field_search(
function verify_entity_query_trail (line 58) | fn verify_entity_query_trail(trail: &QueryTrail<Entity, Walked>) {
function verify_search_result_query_trail (line 64) | fn verify_search_result_query_trail(trail: &QueryTrail<SearchResult, Wal...
function verify_user_query_trail (line 70) | fn verify_user_query_trail(trail: &QueryTrail<User, Walked>) {
type User (line 76) | pub struct User {
method field_id (line 82) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<i32> {
method field_name (line 86) | fn field_name(&self, executor: &Executor<Context>) -> FieldResult<&Strin...
function test_converting_interface_trails (line 92) | fn test_converting_interface_trails() {
function test_converting_interface_trails_negative (line 106) | fn test_converting_interface_trails_negative() {
function test_converting_union_trails (line 119) | fn test_converting_union_trails() {
function test_converting_union_trails_negative (line 135) | fn test_converting_union_trails_negative() {
function query (line 149) | fn query(query: &str) {
FILE: juniper-from-schema/tests/default_argument_values_test.rs
type Query (line 70) | pub struct Query;
method field_int (line 73) | fn field_int(&self, _: &Executor<Context>, arg: i32) -> FieldResult<i32> {
method field_float (line 77) | fn field_float(&self, _: &Executor<Context>, arg: f64) -> FieldResult<f6...
method field_string (line 81) | fn field_string(&self, _: &Executor<Context>, arg: String) -> FieldResul...
method field_boolean (line 85) | fn field_boolean(&self, _: &Executor<Context>, arg: bool) -> FieldResult...
method field_list (line 89) | fn field_list(&self, _: &Executor<Context>, arg: Vec<i32>) -> FieldResul...
method field_enumeration (line 93) | fn field_enumeration(&self, _: &Executor<Context>, arg: Unit) -> FieldRe...
method field_object (line 97) | fn field_object(
method field_object_nullable (line 109) | fn field_object_nullable(
method field_object_nullable_set (line 117) | fn field_object_nullable_set(
method field_object_nullable_partial (line 125) | fn field_object_nullable_partial(
method field_object_nullable_nesting (line 133) | fn field_object_nullable_nesting(
type CoordinateOut (line 142) | pub struct CoordinateOut {
method field_lat (line 148) | fn field_lat(&self, _: &Executor<Context>) -> FieldResult<&f64> {
method field_long (line 152) | fn field_long(&self, _: &Executor<Context>) -> FieldResult<&f64> {
type Context (line 157) | type Context = ();
function test_int (line 160) | fn test_int() {
function test_float (line 169) | fn test_float() {
function test_string (line 178) | fn test_string() {
function test_boolean (line 187) | fn test_boolean() {
function test_list (line 196) | fn test_list() {
function test_enumeration (line 205) | fn test_enumeration() {
function test_object (line 214) | fn test_object() {
function test_object_nullable (line 229) | fn test_object_nullable() {
function test_object_nullable_set (line 238) | fn test_object_nullable_set() {
function test_object_partial (line 253) | fn test_object_partial() {
function test_object_nesting (line 281) | fn test_object_nesting() {
function run_query (line 289) | fn run_query(query: &str) -> Value {
FILE: juniper-from-schema/tests/doc_test.rs
type Query (line 116) | pub struct Query;
method field_query_field (line 119) | fn field_query_field(&self, _: &Executor<Context>, _: InputType) -> Fiel...
method field_entity (line 123) | fn field_entity(
method field_deprecated_field (line 131) | fn field_deprecated_field(&self, _: &Executor<Context>) -> FieldResult<&...
method field_deprecated_field2 (line 135) | fn field_deprecated_field2(&self, _: &Executor<Context>) -> FieldResult<...
method field_search (line 139) | fn field_search(
type User (line 149) | pub struct User {
method field_id (line 155) | fn field_id(&self, _: &Executor<Context>) -> FieldResult<&ID> {
method field_user_type (line 159) | fn field_user_type(&self, _: &Executor<Context>) -> FieldResult<&UserTyp...
method field_interface_field (line 163) | fn field_interface_field(&self, _: &Executor<Context>, _: ID) -> FieldRe...
type Subscription (line 171) | pub struct Subscription;
method field_subscription_field (line 174) | fn field_subscription_field(
type Context (line 183) | pub struct Context;
function test_docs (line 188) | fn test_docs() {
function introspect_schema (line 327) | fn introspect_schema() -> Value {
FILE: juniper-from-schema/tests/end_to_end_test.rs
type Query (line 12) | pub struct Query;
method field_hero (line 15) | fn field_hero(
method field_search (line 39) | fn field_search(
type Mutation (line 62) | pub struct Mutation;
method field_create_review (line 65) | fn field_create_review(
type Review (line 86) | pub struct Review {
method field_episode (line 94) | fn field_episode(&self, executor: &Executor<Context>) -> FieldResult<&Op...
method field_stars (line 98) | fn field_stars(&self, executor: &Executor<Context>) -> FieldResult<&i32> {
method field_commentary (line 102) | fn field_commentary(&self, executor: &Executor<Context>) -> FieldResult<...
type Human (line 108) | pub struct Human {
method field_id (line 114) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<ID> {
method field_name (line 118) | fn field_name(&self, executor: &Executor<Context>) -> FieldResult<&Strin...
type Droid (line 124) | pub struct Droid {
method field_id (line 130) | fn field_id(&self, executor: &Executor<Context>) -> FieldResult<ID> {
method field_name (line 134) | fn field_name(&self, executor: &Executor<Context>) -> FieldResult<&Strin...
type Context (line 139) | pub struct Context {
type Db (line 145) | pub struct Db {
function query_hero (line 150) | fn query_hero() {
function search (line 189) | fn search() {
function run_query (line 215) | fn run_query(query: &str) -> Value {
FILE: juniper-from-schema/tests/launchpad.rs
type Context (line 9) | pub struct Context;
function main (line 13) | fn main() {}
FILE: juniper-from-schema/tests/query_trail_arguments.rs
type Query (line 79) | pub struct Query;
method field_a (line 82) | fn field_a(
type A (line 142) | pub struct A;
method field_b (line 145) | fn field_b(
type B (line 154) | pub struct B;
method field_c (line 157) | fn field_c(
type C (line 166) | pub struct C;
method field_field_with_arg (line 169) | fn field_field_with_arg(
method field_field_with_arg_returning_type (line 193) | fn field_field_with_arg_returning_type(
type D (line 203) | pub struct D;
method field_value (line 206) | fn field_value(&self, executor: &Executor<Context>) -> FieldResult<Strin...
function scalar_values (line 212) | fn scalar_values() {
type Context (line 254) | type Context = ();
function run_query (line 256) | fn run_query(query: &str) -> Value {
FILE: juniper-from-schema/tests/subscriptions/fail/stream_item_type_not_in_subscription_field.rs
type Query (line 24) | pub struct Query;
method field_ping (line 27) | fn field_ping(&self, _: &Executor<Context>) -> FieldResult<&bool> {
type Subscription (line 32) | pub struct Subscription;
method field_users (line 35) | fn field_users<'r, 'a>(
type User (line 44) | pub struct User {
method field_id (line 50) | fn field_id(&self, _: &Executor<Context>) -> FieldResult<&ID> {
method field_name (line 54) | fn field_name(&self, _: &Executor<Context>) -> FieldResult<&String> {
FILE: juniper-from-schema/tests/subscriptions/fail/stream_type_not_in_subscription_field.rs
type Query (line 24) | pub struct Query;
method field_ping (line 27) | fn field_ping(&self, _: &Executor<Context>) -> FieldResult<&bool> {
type Subscription (line 32) | pub struct Subscription;
method field_users (line 35) | fn field_users<'r, 'a>(
type User (line 44) | pub struct User {
method field_id (line 50) | fn field_id(&self, _: &Executor<Context>) -> FieldResult<&ID> {
method field_name (line 54) | fn field_name(&self, _: &Executor<Context>) -> FieldResult<&String> {
FILE: juniper-from-schema/tests/subscriptions/fail/subscriptions_cannot_implement_interfaces.rs
type Query (line 28) | pub struct Query;
method field_ping (line 31) | fn field_ping(&self, _: &Executor<Context>) -> FieldResult<&bool> {
type Subscription (line 36) | pub struct Subscription;
method field_users (line 39) | fn field_users<'r, 'a>(
type User (line 48) | pub struct User {
method field_id (line 54) | fn field_id(&self, _: &Executor<Context>) -> FieldResult<&ID> {
method field_name (line 58) | fn field_name(&self, _: &Executor<Context>) -> FieldResult<&String> {
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_false_stream_type_UserStream_stream_item_infallible_false.rs
method field_users (line 25) | fn field_users<'s, 'r, 'a>(
type UserStream (line 34) | pub struct UserStream;
type Item (line 37) | type Item = FieldResult<User>;
method poll_next (line 39) | fn poll_next(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_false_stream_type_UserStream_stream_item_infallible_true.rs
method field_users (line 25) | fn field_users<'s, 'r, 'a>(
type UserStream (line 34) | pub struct UserStream;
type Item (line 37) | type Item = User;
method poll_next (line 39) | fn poll_next(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_false_stream_type_default_stream_item_infallible_false.rs
method field_users (line 25) | fn field_users<'s, 'r, 'a>(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_false_stream_type_default_stream_item_infallible_true.rs
method field_users (line 25) | fn field_users<'s, 'r, 'a>(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_true_stream_type_UserStream_stream_item_infallible_false.rs
method field_users (line 26) | async fn field_users<'s, 'r, 'a>(
type UserStream (line 35) | pub struct UserStream;
type Item (line 38) | type Item = FieldResult<User>;
method poll_next (line 40) | fn poll_next(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_true_stream_type_UserStream_stream_item_infallible_true.rs
method field_users (line 26) | async fn field_users<'s, 'r, 'a>(
type UserStream (line 35) | pub struct UserStream;
type Item (line 38) | type Item = User;
method poll_next (line 40) | fn poll_next(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_true_stream_type_default_stream_item_infallible_false.rs
method field_users (line 26) | async fn field_users<'s, 'r, 'a>(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_true_stream_type_default_stream_item_infallible_true.rs
method field_users (line 26) | async fn field_users<'s, 'r, 'a>(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_false_stream_type_UserStream_stream_item_infallible_false.rs
method field_users (line 25) | fn field_users<'s, 'r, 'a>(
type UserStream (line 34) | pub struct UserStream;
type Item (line 37) | type Item = FieldResult<User>;
method poll_next (line 39) | fn poll_next(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_false_stream_type_UserStream_stream_item_infallible_true.rs
method field_users (line 25) | fn field_users<'s, 'r, 'a>(
type UserStream (line 34) | pub struct UserStream;
type Item (line 37) | type Item = User;
method poll_next (line 39) | fn poll_next(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_false_stream_type_default_stream_item_infallible_false.rs
method field_users (line 25) | fn field_users<'s, 'r, 'a>(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_false_stream_type_default_stream_item_infallible_true.rs
method field_users (line 25) | fn field_users<'s, 'r, 'a>(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_true_stream_type_UserStream_stream_item_infallible_false.rs
method field_users (line 26) | async fn field_users<'s, 'r, 'a>(
type UserStream (line 35) | pub struct UserStream;
type Item (line 38) | type Item = FieldResult<User>;
method poll_next (line 40) | fn poll_next(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_true_stream_type_UserStream_stream_item_infallible_true.rs
method field_users (line 26) | async fn field_users<'s, 'r, 'a>(
type UserStream (line 35) | pub struct UserStream;
type Item (line 38) | type Item = User;
method poll_next (line 40) | fn poll_next(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_true_stream_type_default_stream_item_infallible_false.rs
method field_users (line 26) | async fn field_users<'s, 'r, 'a>(
FILE: juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_true_stream_type_default_stream_item_infallible_true.rs
method field_users (line 26) | async fn field_users<'s, 'r, 'a>(
FILE: juniper-from-schema/tests/subscriptions/subscription_setup.rs
type BoxStream (line 6) | type BoxStream<T> = Pin<Box<dyn Stream<Item = T> + Send>>;
type User (line 8) | pub struct User {
method field_id (line 14) | fn field_id(&self, _: &Executor<Context>) -> FieldResult<&ID> {
method field_name (line 18) | fn field_name(&self, _: &Executor<Context>) -> FieldResult<&String> {
type Query (line 23) | pub struct Query;
method field_ping (line 26) | fn field_ping(&self, _: &Executor<Context>) -> FieldResult<&bool> {
type Subscription (line 31) | pub struct Subscription;
FILE: juniper-from-schema/tests/version-numbers.rs
function test_html_root_url (line 5) | fn test_html_root_url() {
Condensed preview — 141 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (419K chars).
[
{
"path": ".github/workflows/ci.yml",
"chars": 1945,
"preview": "name: CI\n\non: [push]\n\njobs:\n\n check-formatting:\n name: Check formatting\n runs-on: ubuntu-latest\n steps:\n - "
},
{
"path": ".gitignore",
"chars": 84,
"preview": "/target\n**/*.rs.bk\nCargo.lock\n/tmp\ngenerate-subscription-tests/generated_files/*.rs\n"
},
{
"path": "CHANGELOG.md",
"chars": 9335,
"preview": "# Change Log\n\nAll user visible changes to this project will be documented in this file.\nThis project adheres to [Semanti"
},
{
"path": "Cargo.toml",
"chars": 306,
"preview": "[workspace]\n\nmembers = [\n \"juniper-from-schema\",\n \"juniper-from-schema-proc-macro\",\n \"juniper-from-schema-code-"
},
{
"path": "LICENSE",
"chars": 1111,
"preview": "MIT License Copyright (c) 2020 David Grynnerup Pedersen\n\nPermission is hereby granted, free of charge, to any person obt"
},
{
"path": "README.md",
"chars": 3336,
"preview": "# [juniper-from-schema](https://crates.io/crates/juniper-from-schema)\n\n {\n cd juniper-from-schema\n find examples -name \"*.rs\" |\n while read f; do cargo "
},
{
"path": "generate-subscription-tests/Cargo.toml",
"chars": 262,
"preview": "[package]\nname = \"all-subscription-options\"\nversion = \"0.1.0\"\nauthors = [\"David Pedersen <david.pdrsn@gmail.com>\"]\nediti"
},
{
"path": "generate-subscription-tests/generated_files/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "generate-subscription-tests/src/main.rs",
"chars": 6853,
"preview": "// This crate is used to generate the tests you'll find in \"juniper-from-schema/tests/subscriptions.\"\n//\n// There are qu"
},
{
"path": "juniper-from-schema/Cargo.toml",
"chars": 915,
"preview": "[package]\nversion = \"0.5.2\"\nauthors = [\"David Pedersen <david.pdrsn@gmail.com>\"]\ncategories = [\"web-programming\"]\ndescri"
},
{
"path": "juniper-from-schema/README.md",
"chars": 812,
"preview": "# [juniper-from-schema](https://crates.io/crates/juniper-from-schema)\n[]\n\nuse async_trait::async_trait;\nuse juniper::*;\nuse juniper_from_s"
},
{
"path": "juniper-from-schema/examples/default_argument_values.rs",
"chars": 1114,
"preview": "#![allow(dead_code, unused_variables, unused_imports)]\n\nuse juniper::*;\nuse juniper_from_schema::graphql_schema;\n\ngraphq"
},
{
"path": "juniper-from-schema/examples/enumeration_types.rs",
"chars": 1028,
"preview": "#![allow(dead_code, unused_variables, unused_imports)]\n\nuse juniper::*;\nuse juniper_from_schema::graphql_schema;\n\ngraphq"
},
{
"path": "juniper-from-schema/examples/hello_world.rs",
"chars": 1505,
"preview": "#![allow(dead_code, unused_variables, unused_imports)]\n\nuse juniper::*;\nuse juniper_from_schema::graphql_schema;\n\n// Thi"
},
{
"path": "juniper-from-schema/examples/input_types.rs",
"chars": 1287,
"preview": "#![allow(dead_code, unused_variables, unused_imports)]\n\nuse juniper::*;\nuse juniper_from_schema::graphql_schema;\n\ngraphq"
},
{
"path": "juniper-from-schema/examples/interface.rs",
"chars": 1802,
"preview": "#![allow(dead_code, unused_variables, unused_imports)]\n\nuse juniper::*;\nuse juniper_from_schema::graphql_schema;\n\ngraphq"
},
{
"path": "juniper-from-schema/examples/query_trails.rs",
"chars": 1620,
"preview": "#![allow(clippy::redundant_pattern_matching)]\n#![allow(dead_code, unused_variables, unused_imports)]\n\nuse juniper::*;\nus"
},
{
"path": "juniper-from-schema/examples/subscription.rs",
"chars": 1519,
"preview": "#![allow(dead_code, unused_variables, unused_imports)]\n\nuse async_trait::async_trait;\nuse futures::stream::{Stream, Stre"
},
{
"path": "juniper-from-schema/examples/union_types.rs",
"chars": 1722,
"preview": "#![allow(dead_code, unused_variables, unused_imports)]\n\nuse juniper::*;\nuse juniper_from_schema::graphql_schema;\n\ngraphq"
},
{
"path": "juniper-from-schema/src/lib.rs",
"chars": 56564,
"preview": "//! This library contains a procedural macro that reads a GraphQL schema file, and generates the\n//! corresponding [Juni"
},
{
"path": "juniper-from-schema/tests/compile_fail/docs_on_special_case_scalars.rs",
"chars": 579,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\nuse url::"
},
{
"path": "juniper-from-schema/tests/compile_fail/docs_on_special_case_scalars.stderr",
"chars": 1687,
"preview": "error: proc macro panicked\n --> $DIR/docs_on_special_case_scalars.rs:6:1\n |\n6 | / juniper_from_schema::graphql_schem"
},
{
"path": "juniper-from-schema/tests/compile_fail/invalid_as_ref_type.rs",
"chars": 465,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/compile_fail/invalid_as_ref_type.stderr",
"chars": 774,
"preview": "error: proc macro panicked\n --> $DIR/invalid_as_ref_type.rs:4:1\n |\n4 | / juniper_from_schema::graphql_schema! {\n5 |"
},
{
"path": "juniper-from-schema/tests/compile_fail/invalid_date_time_scalar_directive.rs",
"chars": 527,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\nuse chron"
},
{
"path": "juniper-from-schema/tests/compile_fail/invalid_date_time_scalar_directive.stderr",
"chars": 768,
"preview": "error: proc macro panicked\n --> $DIR/invalid_date_time_scalar_directive.rs:6:1\n |\n6 | / juniper_from_schema::graphql"
},
{
"path": "juniper-from-schema/tests/compile_fail/invalid_juniper_directive_definition.rs",
"chars": 678,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/compile_fail/invalid_juniper_directive_definition.stderr",
"chars": 4232,
"preview": "error: proc macro panicked\n --> $DIR/invalid_juniper_directive_definition.rs:4:1\n |\n4 | / juniper_from_schema::graph"
},
{
"path": "juniper-from-schema/tests/compile_fail/invalid_stream_return_type.rs",
"chars": 1211,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/compile_fail/invalid_stream_return_type.stderr",
"chars": 1857,
"preview": "error: proc macro panicked\n --> $DIR/invalid_stream_return_type.rs:4:1\n |\n4 | / juniper_from_schema::graphql_schema!"
},
{
"path": "juniper-from-schema/tests/compile_fail/scalar_with_built_in_name.rs",
"chars": 601,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/compile_fail/scalar_with_built_in_name.stderr",
"chars": 661,
"preview": "error: proc macro panicked\n --> $DIR/scalar_with_built_in_name.rs:4:1\n |\n4 | / juniper_from_schema::graphql_schema! "
},
{
"path": "juniper-from-schema/tests/compile_fail/snake_cased_fields_on_input_object_types.rs",
"chars": 442,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/compile_fail/snake_cased_fields_on_input_object_types.stderr",
"chars": 771,
"preview": "error: proc macro panicked\n --> $DIR/snake_cased_fields_on_input_object_types.rs:4:1\n |\n4 | / juniper_from_schema::g"
},
{
"path": "juniper-from-schema/tests/compile_fail/snake_cased_fields_on_interfaces.rs",
"chars": 534,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/compile_fail/snake_cased_fields_on_interfaces.stderr",
"chars": 2126,
"preview": "error: proc macro panicked\n --> $DIR/snake_cased_fields_on_interfaces.rs:4:1\n |\n4 | / juniper_from_schema::graphql_s"
},
{
"path": "juniper-from-schema/tests/compile_fail/snake_cased_fields_on_types.rs",
"chars": 403,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/compile_fail/snake_cased_fields_on_types.stderr",
"chars": 821,
"preview": "error: proc macro panicked\n --> $DIR/snake_cased_fields_on_types.rs:4:1\n |\n4 | / juniper_from_schema::graphql_schema"
},
{
"path": "juniper-from-schema/tests/compile_fail/unknown_directive.rs",
"chars": 428,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/compile_fail/unknown_directive.stderr",
"chars": 753,
"preview": "error: proc macro panicked\n --> $DIR/unknown_directive.rs:4:1\n |\n4 | / juniper_from_schema::graphql_schema! {\n5 | |"
},
{
"path": "juniper-from-schema/tests/compile_fail/unsupported_config.rs",
"chars": 413,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/compile_fail/unsupported_config.stderr",
"chars": 363,
"preview": "error: Unknown `graphql_schema_from_file` config `foo`\nSupported configs are `error_type` and `context_type`\n\n --> $DIR/"
},
{
"path": "juniper-from-schema/tests/compile_fail/uppercase_uuid.rs",
"chars": 454,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\nuse uuid:"
},
{
"path": "juniper-from-schema/tests/compile_fail/uppercase_uuid.stderr",
"chars": 778,
"preview": "error: proc macro panicked\n --> $DIR/uppercase_uuid.rs:6:1\n |\n6 | / juniper_from_schema::graphql_schema! {\n7 | | "
},
{
"path": "juniper-from-schema/tests/compile_pass/async.rs",
"chars": 1504,
"preview": "#![allow(\n dead_code,\n unused_mut,\n unused_variables,\n unused_must_use,\n unused_imports\n)]\ninclude!(\"setu"
},
{
"path": "juniper-from-schema/tests/compile_pass/async_as_ref.rs",
"chars": 809,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/async_field_returning_type.rs",
"chars": 840,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\nuse juniper_from_schema::"
},
{
"path": "juniper-from-schema/tests/compile_pass/async_returning_reference.rs",
"chars": 824,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\nuse juniper_from_schema::"
},
{
"path": "juniper-from-schema/tests/compile_pass/correct_executor_signature.rs",
"chars": 369,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/custom_scalar.rs",
"chars": 484,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/customizing_context_name.rs",
"chars": 476,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/customizing_the_error_type.rs",
"chars": 589,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/dates_and_times.rs",
"chars": 685,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\nuse chron"
},
{
"path": "juniper-from-schema/tests/compile_pass/directive_definitions_are_allowed.rs",
"chars": 439,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/compile_pass/empty_mutations.rs",
"chars": 631,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/enums.rs",
"chars": 609,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/field_args.rs",
"chars": 680,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/infallible_directive.rs",
"chars": 1034,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/input_object.rs",
"chars": 550,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/input_object_clone.rs",
"chars": 590,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/input_objects_have_public_fields.rs",
"chars": 683,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\nmod schema {\n use supe"
},
{
"path": "juniper-from-schema/tests/compile_pass/naive_date_time.rs",
"chars": 524,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\nuse chron"
},
{
"path": "juniper-from-schema/tests/compile_pass/non_null_list_non_null_items.rs",
"chars": 377,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/non_null_list_nullable_items.rs",
"chars": 384,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/nullable_list_non_null_items.rs",
"chars": 384,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/nullable_list_nullable_items.rs",
"chars": 414,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/ownership_attributes.rs",
"chars": 829,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/query_trail.rs",
"chars": 1353,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/query_trail_methods_for_interfaces.rs",
"chars": 2287,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/query_trail_methods_for_union_types.rs",
"chars": 3053,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/returning_references.rs",
"chars": 1341,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/setup.rs",
"chars": 381,
"preview": "use juniper::{EmptyMutation, EmptySubscription, Executor, FieldResult, Variables, ID};\nuse std::pin::Pin;\n\npub struct Co"
},
{
"path": "juniper-from-schema/tests/compile_pass/simple_non_null_scalars.rs",
"chars": 777,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/simple_nullable_scalars.rs",
"chars": 805,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\njuniper_from_schema::grap"
},
{
"path": "juniper-from-schema/tests/compile_pass/url.rs",
"chars": 482,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\nuse url::Url;\n\njuniper_fr"
},
{
"path": "juniper-from-schema/tests/compile_pass/uuid.rs",
"chars": 438,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"setup.rs\");\n\nuse uuid::Uuid;\n\njuniper_"
},
{
"path": "juniper-from-schema/tests/compile_pass/valid_juniper_directive_definition.rs",
"chars": 685,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/converting_query_trails_test.rs",
"chars": 3294,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\nuse juniper::{EmptyMutation, Executor, FieldResu"
},
{
"path": "juniper-from-schema/tests/default_argument_values_test.rs",
"chars": 8598,
"preview": "#![allow(clippy::let_unit_value)]\n#![allow(dead_code, unused_variables, unused_imports)]\n\n#[macro_use]\nextern crate juni"
},
{
"path": "juniper-from-schema/tests/doc_test.rs",
"chars": 9580,
"preview": "#![recursion_limit = \"128\"]\n#![allow(dead_code)]\n#![allow(unused_braces)]\n#![deny(deprecated)]\n\nuse assert_json_diff::as"
},
{
"path": "juniper-from-schema/tests/end_to_end_test.rs",
"chars": 5500,
"preview": "#![allow(dead_code, unused_variables, unused_imports)]\n#![allow(unused_braces)]\n\nuse assert_json_diff::assert_json_inclu"
},
{
"path": "juniper-from-schema/tests/launchpad.rs",
"chars": 305,
"preview": "// this file can be used for testing/debugging things before moving them into a trybuild test\n\n#![allow(warnings)]\n\nuse "
},
{
"path": "juniper-from-schema/tests/query_trail_arguments.rs",
"chars": 7194,
"preview": "#![allow(clippy::too_many_arguments)]\n#![allow(dead_code, unused_variables, unused_imports)]\n\n#[macro_use]\nextern crate "
},
{
"path": "juniper-from-schema/tests/schemas/complex_schema.graphql",
"chars": 1968,
"preview": "# From https://github.com/apollographql/starwars-server/blob/master/data/swapiSchema.js\n# Missing:\n# - subscription ty"
},
{
"path": "juniper-from-schema/tests/schemas/customizing_context_name.graphql",
"chars": 57,
"preview": "type Query {\n foo: String!\n}\n\nschema {\n query: Query\n}\n"
},
{
"path": "juniper-from-schema/tests/schemas/doc_schema.graphql",
"chars": 165,
"preview": "schema {\n query: Query\n mutation: Mutation\n}\n\ntype Query {\n helloWorld(name: String!): String! @juniper(ownership: \"o"
},
{
"path": "juniper-from-schema/tests/schemas/doc_test.graphql",
"chars": 1308,
"preview": "schema {\n query: Query\n subscription: Subscription\n}\n\n\"Root query type\"\ntype Query {\n \"queryField desc\"\n que"
},
{
"path": "juniper-from-schema/tests/schemas/original_complex.graphql",
"chars": 4231,
"preview": "# From https://github.com/apollographql/starwars-server/blob/master/data/swapiSchema.js\n# Missing:\n# - subscription ty"
},
{
"path": "juniper-from-schema/tests/schemas/returning_references.graphql",
"chars": 265,
"preview": "type Query {\n userNonNull(id: Int!): User! @juniper(ownership: \"owned\")\n\n userNullable(id: Int!): User @juniper(owners"
},
{
"path": "juniper-from-schema/tests/schemas/very_simple_schema.graphql",
"chars": 60,
"preview": "type Query {\n string: String!\n}\n\nschema { query: Query }\n"
},
{
"path": "juniper-from-schema/tests/subscriptions/fail/stream_item_type_not_in_subscription_field.rs",
"chars": 1232,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/fail/stream_item_type_not_in_subscription_field.stderr",
"chars": 374,
"preview": "error: couldn't read $DIR/tests/subscriptions/fail/../compile_pass/setup.rs: No such file or directory (os error 2)\n -->"
},
{
"path": "juniper-from-schema/tests/subscriptions/fail/stream_type_not_in_subscription_field.rs",
"chars": 1220,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/fail/stream_type_not_in_subscription_field.stderr",
"chars": 369,
"preview": "error: couldn't read $DIR/tests/subscriptions/fail/../compile_pass/setup.rs: No such file or directory (os error 2)\n -->"
},
{
"path": "juniper-from-schema/tests/subscriptions/fail/subscriptions_cannot_implement_interfaces.rs",
"chars": 1255,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../compile_pass/setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/fail/subscriptions_cannot_implement_interfaces.stderr",
"chars": 373,
"preview": "error: couldn't read $DIR/tests/subscriptions/fail/../compile_pass/setup.rs: No such file or directory (os error 2)\n -->"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_false_stream_type_UserStream_stream_item_infallible_false.rs",
"chars": 996,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_false_stream_type_UserStream_stream_item_infallible_true.rs",
"chars": 982,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_false_stream_type_default_stream_item_infallible_false.rs",
"chars": 721,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_false_stream_type_default_stream_item_infallible_true.rs",
"chars": 707,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_true_stream_type_UserStream_stream_item_infallible_false.rs",
"chars": 1016,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_true_stream_type_UserStream_stream_item_infallible_true.rs",
"chars": 1002,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_true_stream_type_default_stream_item_infallible_false.rs",
"chars": 741,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_false_async_true_stream_type_default_stream_item_infallible_true.rs",
"chars": 727,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_false_stream_type_UserStream_stream_item_infallible_false.rs",
"chars": 982,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_false_stream_type_UserStream_stream_item_infallible_true.rs",
"chars": 968,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_false_stream_type_default_stream_item_infallible_false.rs",
"chars": 707,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_false_stream_type_default_stream_item_infallible_true.rs",
"chars": 693,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_true_stream_type_UserStream_stream_item_infallible_false.rs",
"chars": 1002,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_true_stream_type_UserStream_stream_item_infallible_true.rs",
"chars": 988,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_true_stream_type_default_stream_item_infallible_false.rs",
"chars": 727,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/pass/ownership_owned_infallible_true_async_true_stream_type_default_stream_item_infallible_true.rs",
"chars": 713,
"preview": "#![allow(dead_code, unused_variables, unused_must_use, unused_imports)]\ninclude!(\"../subscription_setup.rs\");\n\njuniper_f"
},
{
"path": "juniper-from-schema/tests/subscriptions/subscription_setup.rs",
"chars": 597,
"preview": "include!(\"../compile_pass/setup.rs\");\n\nuse futures::stream::Stream;\nuse async_trait::async_trait;\n\ntype BoxStream<T> = P"
},
{
"path": "juniper-from-schema/tests/version-numbers.rs",
"chars": 126,
"preview": "#[macro_use]\nextern crate version_sync;\n\n#[test]\nfn test_html_root_url() {\n assert_html_root_url_updated!(\"src/lib.rs"
},
{
"path": "juniper-from-schema-build/Cargo.toml",
"chars": 654,
"preview": "[package]\nversion = \"0.5.2\"\nauthors = [\"David Pedersen <david.pdrsn@gmail.com>\"]\ncategories = [\"web-programming\"]\ndescri"
},
{
"path": "juniper-from-schema-build/src/lib.rs",
"chars": 4209,
"preview": "//! Use juniper-from-schema from build.rs\n//!\n//! # Example\n//!\n//! ## Required dependencies\n//!\n//! ```text\n//! [depend"
},
{
"path": "juniper-from-schema-build-tests/basic/Cargo.toml",
"chars": 454,
"preview": "[package]\nname = \"basic\"\nversion = \"0.1.0\"\nauthors = [\"David Pedersen <david.pdrsn@gmail.com>\"]\nedition = \"2018\"\npublish"
},
{
"path": "juniper-from-schema-build-tests/basic/build.rs",
"chars": 221,
"preview": "fn main() {\n juniper_from_schema_build::compile_schema_literal(\n r#\"\n schema {\n query: Query"
},
{
"path": "juniper-from-schema-build-tests/basic/src/lib.rs",
"chars": 343,
"preview": "#![allow(unused_braces)]\n\nuse juniper::{Executor, FieldResult};\n\njuniper_from_schema::include_schema!();\n\n#[derive(Debug"
},
{
"path": "juniper-from-schema-build-tests/file/Cargo.toml",
"chars": 453,
"preview": "[package]\nname = \"file\"\nversion = \"0.1.0\"\nauthors = [\"David Pedersen <david.pdrsn@gmail.com>\"]\nedition = \"2018\"\npublish "
},
{
"path": "juniper-from-schema-build-tests/file/build.rs",
"chars": 179,
"preview": "fn main() {\n juniper_from_schema_build::configure_for_file(\"schema.graphql\")\n .context_type(\"()\")\n .err"
},
{
"path": "juniper-from-schema-build-tests/file/schema.graphql",
"chars": 63,
"preview": "schema {\n query: Query\n}\n\ntype Query {\n ping: Boolean!\n}\n"
},
{
"path": "juniper-from-schema-build-tests/file/src/lib.rs",
"chars": 509,
"preview": "#![allow(unused_braces)]\n\nuse juniper::{Executor, FieldError, IntoFieldError};\n\njuniper_from_schema::include_schema!();\n"
},
{
"path": "juniper-from-schema-code-gen/Cargo.toml",
"chars": 707,
"preview": "[package]\nversion = \"0.5.2\"\nauthors = [\"David Pedersen <david.pdrsn@gmail.com>\"]\ncategories = [\"web-programming\"]\ndescri"
},
{
"path": "juniper-from-schema-code-gen/src/ast_pass/code_gen_pass/gen_query_trails.rs",
"chars": 32775,
"preview": "use super::CodeGenPass;\nuse crate::ast_pass::{\n error::ErrorKind,\n schema_visitor::{visit_document, SchemaVisitor}"
},
{
"path": "juniper-from-schema-code-gen/src/ast_pass/code_gen_pass/mod.rs",
"chars": 80823,
"preview": "mod gen_query_trails;\n\nuse super::{\n directive_parsing::*, error::Error, schema_visitor::*, type_name, validations::*"
},
{
"path": "juniper-from-schema-code-gen/src/ast_pass/directive_parsing.rs",
"chars": 14823,
"preview": "use crate::ast_pass::{\n code_gen_pass::CodeGenPass,\n error::{self, ErrorKind, Juniper, UnsupportedDirectiveKind, V"
},
{
"path": "juniper-from-schema-code-gen/src/ast_pass/error.rs",
"chars": 14016,
"preview": "use colored::*;\nuse graphql_parser::{query::Value, Pos};\nuse std::fmt::{self, Write};\n\n#[derive(Debug, Clone, Eq, Partia"
},
{
"path": "juniper-from-schema-code-gen/src/ast_pass/mod.rs",
"chars": 10156,
"preview": "pub mod code_gen_pass;\npub mod directive_parsing;\npub mod error;\npub mod schema_visitor;\npub mod validations;\n\nuse self:"
},
{
"path": "juniper-from-schema-code-gen/src/ast_pass/schema_visitor.rs",
"chars": 10756,
"preview": "#![deny(unused_variables)]\n\nuse graphql_parser::{\n schema,\n schema::{Definition, TypeDefinition, TypeExtension},\n}"
},
{
"path": "juniper-from-schema-code-gen/src/ast_pass/validations.rs",
"chars": 2265,
"preview": "use std::collections::BTreeSet;\n\nuse super::{error::Error, schema_visitor::SchemaVisitor, EmitError, ErrorKind};\nuse gra"
},
{
"path": "juniper-from-schema-code-gen/src/lib.rs",
"chars": 5744,
"preview": "//! See the docs for \"juniper-from-schema\" for more info about this.\n\n#![deny(\n unused_imports,\n mutable_borrow_re"
},
{
"path": "juniper-from-schema-proc-macro/Cargo.toml",
"chars": 767,
"preview": "[package]\nversion = \"0.5.2\"\nauthors = [\"David Pedersen <david.pdrsn@gmail.com>\"]\ncategories = [\"web-programming\"]\ndescri"
},
{
"path": "juniper-from-schema-proc-macro/README.md",
"chars": 286,
"preview": "# juniper-from-schema-proc-macro\n\nInternal crate for [juniper-from-schema](https://crates.io/crates/juniper-from-schema)"
},
{
"path": "juniper-from-schema-proc-macro/src/lib.rs",
"chars": 2397,
"preview": "//! See the docs for \"juniper-from-schema\" for more info about this.\n\n#![deny(\n unused_imports,\n mutable_borrow_re"
},
{
"path": "juniper-from-schema-proc-macro/src/parse_input.rs",
"chars": 1940,
"preview": "use std::{fmt::Write, path::PathBuf};\nuse syn::{\n self,\n parse::{Parse, ParseStream},\n Ident, Token, Type,\n};\n\n"
},
{
"path": "juniper-from-schema-proc-macro/tests/version-numbers.rs",
"chars": 126,
"preview": "#[macro_use]\nextern crate version_sync;\n\n#[test]\nfn test_html_root_url() {\n assert_html_root_url_updated!(\"src/lib.rs"
},
{
"path": "rustfmt.toml",
"chars": 17,
"preview": "edition = \"2018\"\n"
}
]
About this extraction
This page contains the full source code of the davidpdrsn/juniper-from-schema GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 141 files (380.7 KB), approximately 96.5k tokens, and a symbol index with 757 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.