2020-05-02 04:24:01 +02:00
|
|
|
|
//!
|
|
|
|
|
|
|
|
|
|
use crate::util::duplicate::Duplicate;
|
|
|
|
|
use proc_macro2::Span;
|
|
|
|
|
use proc_macro_error::{Diagnostic, Level};
|
|
|
|
|
use std::fmt;
|
|
|
|
|
|
2020-06-04 11:19:01 +03:00
|
|
|
|
/// URL of the GraphQL specification (June 2018 Edition).
|
2020-07-16 07:41:09 -10:00
|
|
|
|
pub const SPEC_URL: &str = "https://spec.graphql.org/June2018/";
|
2020-05-02 04:24:01 +02:00
|
|
|
|
|
|
|
|
|
pub enum GraphQLScope {
|
Make interfaces great again! (#682)
* Bootstrap
* Upd
* Bootstrap macro
* Revert stuff
* Correct PoC to compile
* Bootstrap #[graphql_interface] expansion
* Bootstrap #[graphql_interface] meta parsing
* Bootstrap #[graphql_interface] very basic code generation [skip ci]
* Upd trait code generation and fix keywords usage [skip ci]
* Expand trait impls [skip ci]
* Tune up objects [skip ci]
* Finally! Complies at least... [skip ci]
* Parse meta for fields and its arguments [skip ci]
- also, refactor and bikeshed new macros code
* Impl filling fields meta and bootstrap field resolution [skip ci]
* Poking with fields resolution [skip ci]
* Solve Rust's teen async HRTB problems [skip ci]
* Start parsing trait methods [skip ci]
* Finish parsing fields from trait methods [skip ci]
* Autodetect trait asyncness and allow to specify it [skip ci]
* Allow to autogenerate trait object alias via attribute
* Support generics in trait definition and asyncify them correctly
* Temporary disable explicit async
* Cover arguments and custom names/descriptions in tests
* Re-enable tests with explicit async and fix the codegen to satisfy it
* Check implementers are registered in schema and vice versa
* Check argument camelCases
* Test argument defaults, and allow Into coercions for them
* Re-enable markers
* Re-enable markers and relax Sized requirement on IsInputType/IsOutputType marker traits
* Revert 'juniper_actix' fmt
* Fix missing marks for object
* Fix subscriptions marks
* Deduce result type correctly via traits
* Final fixes
* Fmt
* Restore marks checking
* Support custom ScalarValue
* Cover deprecations with tests
* Impl dowcasting via methods
* Impl dowcasting via external functions
* Support custom context, vol. 1
* Support custom context, vol. 2
* Cover fallible field with test
* Impl explicit generic ScalarValue, vol.1
* Impl explicit generic ScalarValue, vol.2
* Allow passing executor into methods
* Generating enum, vol.1
* Generating enum, vol.2
* Generating enum, vol.3
* Generating enum, vol.3
* Generating enum, vol.4
* Generating enum, vol.5
* Generating enum, vol.6
* Generating enum, vol.7
* Generating enum, vol.8
* Refactor juniper stuff
* Fix juniper tests, vol.1
* Fix juniper tests, vol.2
* Polish 'juniper' crate changes, vol.1
* Polish 'juniper' crate changes, vol.2
* Remove redundant stuf
* Polishing 'juniper_codegen', vol.1
* Polishing 'juniper_codegen', vol.2
* Polishing 'juniper_codegen', vol.3
* Polishing 'juniper_codegen', vol.4
* Polishing 'juniper_codegen', vol.5
* Polishing 'juniper_codegen', vol.6
* Polishing 'juniper_codegen', vol.7
* Polishing 'juniper_codegen', vol.8
* Polishing 'juniper_codegen', vol.9
* Fix other crates tests and make Clippy happier
* Fix examples
* Add codegen failure tests, vol. 1
* Add codegen failure tests, vol. 2
* Add codegen failure tests, vol.3
* Fix codegen failure tests accordingly to latest nightly Rust
* Fix codegen when interface has no implementers
* Fix warnings in book tests
* Describing new interfaces in Book, vol.1
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
2020-10-06 10:21:01 +03:00
|
|
|
|
InterfaceAttr,
|
2022-04-01 21:10:45 +03:00
|
|
|
|
InterfaceDerive,
|
2021-08-11 17:41:49 +03:00
|
|
|
|
ObjectAttr,
|
|
|
|
|
ObjectDerive,
|
2022-02-24 18:12:17 +03:00
|
|
|
|
ScalarAttr,
|
|
|
|
|
ScalarDerive,
|
2022-03-03 16:49:35 +03:00
|
|
|
|
ScalarValueDerive,
|
2020-06-04 11:19:01 +03:00
|
|
|
|
UnionAttr,
|
Make interfaces great again! (#682)
* Bootstrap
* Upd
* Bootstrap macro
* Revert stuff
* Correct PoC to compile
* Bootstrap #[graphql_interface] expansion
* Bootstrap #[graphql_interface] meta parsing
* Bootstrap #[graphql_interface] very basic code generation [skip ci]
* Upd trait code generation and fix keywords usage [skip ci]
* Expand trait impls [skip ci]
* Tune up objects [skip ci]
* Finally! Complies at least... [skip ci]
* Parse meta for fields and its arguments [skip ci]
- also, refactor and bikeshed new macros code
* Impl filling fields meta and bootstrap field resolution [skip ci]
* Poking with fields resolution [skip ci]
* Solve Rust's teen async HRTB problems [skip ci]
* Start parsing trait methods [skip ci]
* Finish parsing fields from trait methods [skip ci]
* Autodetect trait asyncness and allow to specify it [skip ci]
* Allow to autogenerate trait object alias via attribute
* Support generics in trait definition and asyncify them correctly
* Temporary disable explicit async
* Cover arguments and custom names/descriptions in tests
* Re-enable tests with explicit async and fix the codegen to satisfy it
* Check implementers are registered in schema and vice versa
* Check argument camelCases
* Test argument defaults, and allow Into coercions for them
* Re-enable markers
* Re-enable markers and relax Sized requirement on IsInputType/IsOutputType marker traits
* Revert 'juniper_actix' fmt
* Fix missing marks for object
* Fix subscriptions marks
* Deduce result type correctly via traits
* Final fixes
* Fmt
* Restore marks checking
* Support custom ScalarValue
* Cover deprecations with tests
* Impl dowcasting via methods
* Impl dowcasting via external functions
* Support custom context, vol. 1
* Support custom context, vol. 2
* Cover fallible field with test
* Impl explicit generic ScalarValue, vol.1
* Impl explicit generic ScalarValue, vol.2
* Allow passing executor into methods
* Generating enum, vol.1
* Generating enum, vol.2
* Generating enum, vol.3
* Generating enum, vol.3
* Generating enum, vol.4
* Generating enum, vol.5
* Generating enum, vol.6
* Generating enum, vol.7
* Generating enum, vol.8
* Refactor juniper stuff
* Fix juniper tests, vol.1
* Fix juniper tests, vol.2
* Polish 'juniper' crate changes, vol.1
* Polish 'juniper' crate changes, vol.2
* Remove redundant stuf
* Polishing 'juniper_codegen', vol.1
* Polishing 'juniper_codegen', vol.2
* Polishing 'juniper_codegen', vol.3
* Polishing 'juniper_codegen', vol.4
* Polishing 'juniper_codegen', vol.5
* Polishing 'juniper_codegen', vol.6
* Polishing 'juniper_codegen', vol.7
* Polishing 'juniper_codegen', vol.8
* Polishing 'juniper_codegen', vol.9
* Fix other crates tests and make Clippy happier
* Fix examples
* Add codegen failure tests, vol. 1
* Add codegen failure tests, vol. 2
* Add codegen failure tests, vol.3
* Fix codegen failure tests accordingly to latest nightly Rust
* Fix codegen when interface has no implementers
* Fix warnings in book tests
* Describing new interfaces in Book, vol.1
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
2020-10-06 10:21:01 +03:00
|
|
|
|
UnionDerive,
|
2020-05-02 04:24:01 +02:00
|
|
|
|
DeriveInputObject,
|
|
|
|
|
DeriveEnum,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl GraphQLScope {
|
2020-06-04 11:19:01 +03:00
|
|
|
|
pub fn spec_section(&self) -> &str {
|
2020-05-02 04:24:01 +02:00
|
|
|
|
match self {
|
2022-04-01 21:10:45 +03:00
|
|
|
|
Self::InterfaceAttr | Self::InterfaceDerive => "#sec-Interfaces",
|
2021-08-11 17:41:49 +03:00
|
|
|
|
Self::ObjectAttr | Self::ObjectDerive => "#sec-Objects",
|
2022-02-24 18:12:17 +03:00
|
|
|
|
Self::ScalarAttr | Self::ScalarDerive => "#sec-Scalars",
|
2022-03-03 16:49:35 +03:00
|
|
|
|
Self::ScalarValueDerive => "#sec-Scalars.Built-in-Scalars",
|
Make interfaces great again! (#682)
* Bootstrap
* Upd
* Bootstrap macro
* Revert stuff
* Correct PoC to compile
* Bootstrap #[graphql_interface] expansion
* Bootstrap #[graphql_interface] meta parsing
* Bootstrap #[graphql_interface] very basic code generation [skip ci]
* Upd trait code generation and fix keywords usage [skip ci]
* Expand trait impls [skip ci]
* Tune up objects [skip ci]
* Finally! Complies at least... [skip ci]
* Parse meta for fields and its arguments [skip ci]
- also, refactor and bikeshed new macros code
* Impl filling fields meta and bootstrap field resolution [skip ci]
* Poking with fields resolution [skip ci]
* Solve Rust's teen async HRTB problems [skip ci]
* Start parsing trait methods [skip ci]
* Finish parsing fields from trait methods [skip ci]
* Autodetect trait asyncness and allow to specify it [skip ci]
* Allow to autogenerate trait object alias via attribute
* Support generics in trait definition and asyncify them correctly
* Temporary disable explicit async
* Cover arguments and custom names/descriptions in tests
* Re-enable tests with explicit async and fix the codegen to satisfy it
* Check implementers are registered in schema and vice versa
* Check argument camelCases
* Test argument defaults, and allow Into coercions for them
* Re-enable markers
* Re-enable markers and relax Sized requirement on IsInputType/IsOutputType marker traits
* Revert 'juniper_actix' fmt
* Fix missing marks for object
* Fix subscriptions marks
* Deduce result type correctly via traits
* Final fixes
* Fmt
* Restore marks checking
* Support custom ScalarValue
* Cover deprecations with tests
* Impl dowcasting via methods
* Impl dowcasting via external functions
* Support custom context, vol. 1
* Support custom context, vol. 2
* Cover fallible field with test
* Impl explicit generic ScalarValue, vol.1
* Impl explicit generic ScalarValue, vol.2
* Allow passing executor into methods
* Generating enum, vol.1
* Generating enum, vol.2
* Generating enum, vol.3
* Generating enum, vol.3
* Generating enum, vol.4
* Generating enum, vol.5
* Generating enum, vol.6
* Generating enum, vol.7
* Generating enum, vol.8
* Refactor juniper stuff
* Fix juniper tests, vol.1
* Fix juniper tests, vol.2
* Polish 'juniper' crate changes, vol.1
* Polish 'juniper' crate changes, vol.2
* Remove redundant stuf
* Polishing 'juniper_codegen', vol.1
* Polishing 'juniper_codegen', vol.2
* Polishing 'juniper_codegen', vol.3
* Polishing 'juniper_codegen', vol.4
* Polishing 'juniper_codegen', vol.5
* Polishing 'juniper_codegen', vol.6
* Polishing 'juniper_codegen', vol.7
* Polishing 'juniper_codegen', vol.8
* Polishing 'juniper_codegen', vol.9
* Fix other crates tests and make Clippy happier
* Fix examples
* Add codegen failure tests, vol. 1
* Add codegen failure tests, vol. 2
* Add codegen failure tests, vol.3
* Fix codegen failure tests accordingly to latest nightly Rust
* Fix codegen when interface has no implementers
* Fix warnings in book tests
* Describing new interfaces in Book, vol.1
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
2020-10-06 10:21:01 +03:00
|
|
|
|
Self::UnionAttr | Self::UnionDerive => "#sec-Unions",
|
2020-06-04 11:19:01 +03:00
|
|
|
|
Self::DeriveInputObject => "#sec-Input-Objects",
|
|
|
|
|
Self::DeriveEnum => "#sec-Enums",
|
2020-05-02 04:24:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl fmt::Display for GraphQLScope {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
|
let name = match self {
|
2022-04-01 21:10:45 +03:00
|
|
|
|
Self::InterfaceAttr | Self::InterfaceDerive => "interface",
|
2021-08-11 17:41:49 +03:00
|
|
|
|
Self::ObjectAttr | Self::ObjectDerive => "object",
|
2022-02-24 18:12:17 +03:00
|
|
|
|
Self::ScalarAttr | Self::ScalarDerive => "scalar",
|
2022-03-03 16:49:35 +03:00
|
|
|
|
Self::ScalarValueDerive => "built-in scalars",
|
Make interfaces great again! (#682)
* Bootstrap
* Upd
* Bootstrap macro
* Revert stuff
* Correct PoC to compile
* Bootstrap #[graphql_interface] expansion
* Bootstrap #[graphql_interface] meta parsing
* Bootstrap #[graphql_interface] very basic code generation [skip ci]
* Upd trait code generation and fix keywords usage [skip ci]
* Expand trait impls [skip ci]
* Tune up objects [skip ci]
* Finally! Complies at least... [skip ci]
* Parse meta for fields and its arguments [skip ci]
- also, refactor and bikeshed new macros code
* Impl filling fields meta and bootstrap field resolution [skip ci]
* Poking with fields resolution [skip ci]
* Solve Rust's teen async HRTB problems [skip ci]
* Start parsing trait methods [skip ci]
* Finish parsing fields from trait methods [skip ci]
* Autodetect trait asyncness and allow to specify it [skip ci]
* Allow to autogenerate trait object alias via attribute
* Support generics in trait definition and asyncify them correctly
* Temporary disable explicit async
* Cover arguments and custom names/descriptions in tests
* Re-enable tests with explicit async and fix the codegen to satisfy it
* Check implementers are registered in schema and vice versa
* Check argument camelCases
* Test argument defaults, and allow Into coercions for them
* Re-enable markers
* Re-enable markers and relax Sized requirement on IsInputType/IsOutputType marker traits
* Revert 'juniper_actix' fmt
* Fix missing marks for object
* Fix subscriptions marks
* Deduce result type correctly via traits
* Final fixes
* Fmt
* Restore marks checking
* Support custom ScalarValue
* Cover deprecations with tests
* Impl dowcasting via methods
* Impl dowcasting via external functions
* Support custom context, vol. 1
* Support custom context, vol. 2
* Cover fallible field with test
* Impl explicit generic ScalarValue, vol.1
* Impl explicit generic ScalarValue, vol.2
* Allow passing executor into methods
* Generating enum, vol.1
* Generating enum, vol.2
* Generating enum, vol.3
* Generating enum, vol.3
* Generating enum, vol.4
* Generating enum, vol.5
* Generating enum, vol.6
* Generating enum, vol.7
* Generating enum, vol.8
* Refactor juniper stuff
* Fix juniper tests, vol.1
* Fix juniper tests, vol.2
* Polish 'juniper' crate changes, vol.1
* Polish 'juniper' crate changes, vol.2
* Remove redundant stuf
* Polishing 'juniper_codegen', vol.1
* Polishing 'juniper_codegen', vol.2
* Polishing 'juniper_codegen', vol.3
* Polishing 'juniper_codegen', vol.4
* Polishing 'juniper_codegen', vol.5
* Polishing 'juniper_codegen', vol.6
* Polishing 'juniper_codegen', vol.7
* Polishing 'juniper_codegen', vol.8
* Polishing 'juniper_codegen', vol.9
* Fix other crates tests and make Clippy happier
* Fix examples
* Add codegen failure tests, vol. 1
* Add codegen failure tests, vol. 2
* Add codegen failure tests, vol.3
* Fix codegen failure tests accordingly to latest nightly Rust
* Fix codegen when interface has no implementers
* Fix warnings in book tests
* Describing new interfaces in Book, vol.1
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
2020-10-06 10:21:01 +03:00
|
|
|
|
Self::UnionAttr | Self::UnionDerive => "union",
|
2020-06-04 11:19:01 +03:00
|
|
|
|
Self::DeriveInputObject => "input object",
|
|
|
|
|
Self::DeriveEnum => "enum",
|
2020-05-02 04:24:01 +02:00
|
|
|
|
};
|
|
|
|
|
write!(f, "GraphQL {}", name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(unused_variables)]
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub enum UnsupportedAttribute {
|
|
|
|
|
Skip,
|
|
|
|
|
Interface,
|
|
|
|
|
Scalar,
|
|
|
|
|
Deprecation,
|
|
|
|
|
Default,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl GraphQLScope {
|
2020-06-04 11:19:01 +03:00
|
|
|
|
fn spec_link(&self) -> String {
|
|
|
|
|
format!("{}{}", SPEC_URL, self.spec_section())
|
2020-05-02 04:24:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-04 11:19:01 +03:00
|
|
|
|
pub fn custom<S: AsRef<str>>(&self, span: Span, msg: S) -> Diagnostic {
|
2020-05-02 04:24:01 +02:00
|
|
|
|
Diagnostic::spanned(span, Level::Error, format!("{} {}", self, msg.as_ref()))
|
2020-06-04 11:19:01 +03:00
|
|
|
|
.note(self.spec_link())
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 17:41:49 +03:00
|
|
|
|
pub fn error(&self, err: syn::Error) -> Diagnostic {
|
|
|
|
|
Diagnostic::spanned(err.span(), Level::Error, format!("{} {}", self, err))
|
|
|
|
|
.note(self.spec_link())
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-04 11:19:01 +03:00
|
|
|
|
pub fn emit_custom<S: AsRef<str>>(&self, span: Span, msg: S) {
|
|
|
|
|
self.custom(span, msg).emit()
|
2020-05-02 04:24:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn custom_error<S: AsRef<str>>(&self, span: Span, msg: S) -> syn::Error {
|
|
|
|
|
syn::Error::new(span, format!("{} {}", self, msg.as_ref()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn unsupported_attribute(&self, attribute: Span, kind: UnsupportedAttribute) {
|
|
|
|
|
Diagnostic::spanned(
|
|
|
|
|
attribute,
|
|
|
|
|
Level::Error,
|
|
|
|
|
format!("attribute `{:?}` can not be used at the top level of {}", kind, self),
|
|
|
|
|
)
|
|
|
|
|
.note("The macro is known to Juniper. However, not all valid #[graphql] attributes are available for each macro".to_string())
|
|
|
|
|
.emit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn unsupported_attribute_within(&self, attribute: Span, kind: UnsupportedAttribute) {
|
|
|
|
|
Diagnostic::spanned(
|
|
|
|
|
attribute,
|
|
|
|
|
Level::Error,
|
|
|
|
|
format!("attribute `{:?}` can not be used inside of {}", kind, self),
|
|
|
|
|
)
|
|
|
|
|
.note("The macro is known to Juniper. However, not all valid #[graphql] attributes are available for each macro".to_string())
|
|
|
|
|
.emit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn not_empty(&self, container: Span) {
|
|
|
|
|
Diagnostic::spanned(
|
|
|
|
|
container,
|
|
|
|
|
Level::Error,
|
|
|
|
|
format!("{} expects at least one field", self),
|
|
|
|
|
)
|
2020-06-04 11:19:01 +03:00
|
|
|
|
.note(self.spec_link())
|
2020-05-02 04:24:01 +02:00
|
|
|
|
.emit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn duplicate<'a, T: syn::spanned::Spanned + 'a>(
|
|
|
|
|
&self,
|
|
|
|
|
duplicates: impl IntoIterator<Item = &'a Duplicate<T>>,
|
|
|
|
|
) {
|
|
|
|
|
duplicates
|
|
|
|
|
.into_iter()
|
|
|
|
|
.for_each(|dup| {
|
2022-02-24 18:12:17 +03:00
|
|
|
|
dup.spanned[1..]
|
2020-05-02 04:24:01 +02:00
|
|
|
|
.iter()
|
|
|
|
|
.for_each(|spanned| {
|
|
|
|
|
Diagnostic::spanned(
|
|
|
|
|
spanned.span(),
|
|
|
|
|
Level::Error,
|
|
|
|
|
format!(
|
|
|
|
|
"{} does not allow fields with the same name",
|
|
|
|
|
self
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.help(format!("There is at least one other field with the same name `{}`, possibly renamed via the #[graphql] attribute", dup.name))
|
2020-06-04 11:19:01 +03:00
|
|
|
|
.note(self.spec_link())
|
2020-05-02 04:24:01 +02:00
|
|
|
|
.emit();
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn no_double_underscore(&self, field: Span) {
|
|
|
|
|
Diagnostic::spanned(
|
|
|
|
|
field,
|
|
|
|
|
Level::Error,
|
2020-06-04 11:19:01 +03:00
|
|
|
|
"All types and directives defined within a schema must not have a name which begins \
|
|
|
|
|
with `__` (two underscores), as this is used exclusively by GraphQL’s introspection \
|
|
|
|
|
system."
|
|
|
|
|
.into(),
|
2020-05-02 04:24:01 +02:00
|
|
|
|
)
|
2020-06-04 11:19:01 +03:00
|
|
|
|
.note(format!("{}#sec-Schema", SPEC_URL))
|
|
|
|
|
.emit();
|
2020-05-02 04:24:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|