Skip to content

Commit 075271e

Browse files
committed
Renew GraphQL type system definition and canonical introspection query
1 parent 50ecaf5 commit 075271e

File tree

9 files changed

+204
-198
lines changed

9 files changed

+204
-198
lines changed

juniper/benches/bench.rs

Lines changed: 11 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ fn query_type_name(b: &mut Bencher) {
1717
EmptySubscription::<Database>::new(),
1818
);
1919

20-
let doc = r#"
21-
query IntrospectionQueryTypeQuery {
22-
__schema {
23-
queryType {
24-
name
25-
}
26-
}
27-
}"#;
20+
// language=GraphQL
21+
let query = "query IntrospectionQueryTypeQuery {
22+
__schema {
23+
queryType {
24+
name
25+
}
26+
}
27+
}";
2828

29-
b.iter(|| execute_sync(doc, None, &schema, &graphql_vars! {}, &database));
29+
b.iter(|| execute_sync(query, None, &schema, &graphql_vars! {}, &database));
3030
}
3131

3232
fn introspection_query(b: &mut Bencher) {
@@ -42,101 +42,9 @@ fn introspection_query(b: &mut Bencher) {
4242
EmptySubscription::<Database>::new(),
4343
);
4444

45-
let doc = r#"
46-
query IntrospectionQuery {
47-
__schema {
48-
queryType { name }
49-
mutationType { name }
50-
subscriptionType { name }
51-
types {
52-
...FullType
53-
}
54-
directives {
55-
name
56-
description
57-
locations
58-
args {
59-
...InputValue
60-
}
61-
}
62-
}
63-
}
64-
65-
fragment FullType on __Type {
66-
kind
67-
name
68-
description
69-
fields(includeDeprecated: true) {
70-
name
71-
description
72-
args {
73-
...InputValue
74-
}
75-
type {
76-
...TypeRef
77-
}
78-
isDeprecated
79-
deprecationReason
80-
}
81-
inputFields {
82-
...InputValue
83-
}
84-
interfaces {
85-
...TypeRef
86-
}
87-
enumValues(includeDeprecated: true) {
88-
name
89-
description
90-
isDeprecated
91-
deprecationReason
92-
}
93-
possibleTypes {
94-
...TypeRef
95-
}
96-
}
97-
98-
fragment InputValue on __InputValue {
99-
name
100-
description
101-
type { ...TypeRef }
102-
defaultValue
103-
}
104-
105-
fragment TypeRef on __Type {
106-
kind
107-
name
108-
ofType {
109-
kind
110-
name
111-
ofType {
112-
kind
113-
name
114-
ofType {
115-
kind
116-
name
117-
ofType {
118-
kind
119-
name
120-
ofType {
121-
kind
122-
name
123-
ofType {
124-
kind
125-
name
126-
ofType {
127-
kind
128-
name
129-
}
130-
}
131-
}
132-
}
133-
}
134-
}
135-
}
136-
}
137-
"#;
45+
let query = include_str!("../src/introspection/query.graphql");
13846

139-
b.iter(|| execute_sync(doc, None, &schema, &graphql_vars! {}, &database));
47+
b.iter(|| execute_sync(query, None, &schema, &graphql_vars! {}, &database));
14048
}
14149

14250
benchmark_group!(queries, query_type_name, introspection_query);

juniper/src/executor/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ impl<S> Registry<S> {
12171217
Argument::new(name, self.get_type::<T>(info))
12181218
}
12191219

1220-
/// Creates an [`Argument`] with the provided default `value`.
1220+
/// Creates an [`Argument`] with the provided `name` and default `value`.
12211221
pub fn arg_with_default<T>(
12221222
&mut self,
12231223
name: impl Into<ArcStr>,
@@ -1228,7 +1228,8 @@ impl<S> Registry<S> {
12281228
T: GraphQLType<S> + ToInputValue<S> + FromInputValue<S>,
12291229
S: ScalarValue,
12301230
{
1231-
Argument::new(name, self.get_type::<T>(info)).default_value(value.to_input_value())
1231+
self.arg::<T>(name, info)
1232+
.default_value(value.to_input_value())
12321233
}
12331234

12341235
fn insert_placeholder(&mut self, name: Name, of_type: Type) {

juniper/src/introspection/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/// From <https://github.com/graphql/graphql-js/blob/90bd6ff72625173dd39a1f82cfad9336cfad8f65/src/utilities/getIntrospectionQuery.ts#L62>
21
pub(crate) const INTROSPECTION_QUERY: &str = include_str!("./query.graphql");
32
pub(crate) const INTROSPECTION_QUERY_WITHOUT_DESCRIPTIONS: &str =
43
include_str!("./query_without_descriptions.graphql");
54

6-
/// The desired GraphQL introspection format for the canonical query
7-
/// (<https://github.com/graphql/graphql-js/blob/90bd6ff72625173dd39a1f82cfad9336cfad8f65/src/utilities/getIntrospectionQuery.ts#L62>)
5+
/// Desired GraphQL introspection format for the [canonical introspection query][0].
6+
///
7+
/// [0]: https://github.com/graphql/graphql-js/blob/v16.11.0/src/utilities/getIntrospectionQuery.ts#L75
88
#[derive(Clone, Copy, Debug, Default)]
99
pub enum IntrospectionFormat {
1010
/// The canonical GraphQL introspection query.

juniper/src/introspection/query.graphql

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
query IntrospectionQuery {
22
__schema {
33
description
4-
queryType {
5-
name
6-
}
7-
mutationType {
8-
name
9-
}
10-
subscriptionType {
11-
name
12-
}
4+
queryType { name kind }
5+
mutationType { name kind }
6+
subscriptionType { name kind }
137
types {
148
...FullType
159
}
@@ -18,21 +12,23 @@ query IntrospectionQuery {
1812
description
1913
isRepeatable
2014
locations
21-
args {
15+
args(includeDeprecated: true) {
2216
...InputValue
2317
}
2418
}
2519
}
2620
}
21+
2722
fragment FullType on __Type {
2823
kind
2924
name
3025
description
31-
specifiedByUrl
26+
specifiedByURL
27+
isOneOf
3228
fields(includeDeprecated: true) {
3329
name
3430
description
35-
args {
31+
args(includeDeprecated: true) {
3632
...InputValue
3733
}
3834
type {
@@ -41,7 +37,7 @@ fragment FullType on __Type {
4137
isDeprecated
4238
deprecationReason
4339
}
44-
inputFields {
40+
inputFields(includeDeprecated: true) {
4541
...InputValue
4642
}
4743
interfaces {
@@ -57,14 +53,16 @@ fragment FullType on __Type {
5753
...TypeRef
5854
}
5955
}
56+
6057
fragment InputValue on __InputValue {
6158
name
6259
description
63-
type {
64-
...TypeRef
65-
}
60+
type { ...TypeRef }
6661
defaultValue
62+
isDeprecated
63+
deprecationReason
6764
}
65+
6866
fragment TypeRef on __Type {
6967
kind
7068
name
@@ -89,11 +87,19 @@ fragment TypeRef on __Type {
8987
ofType {
9088
kind
9189
name
90+
ofType {
91+
kind
92+
name
93+
ofType {
94+
kind
95+
name
96+
}
97+
}
9298
}
9399
}
94100
}
95101
}
96102
}
97103
}
98104
}
99-
}
105+
}

juniper/src/introspection/query_without_descriptions.graphql

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
query IntrospectionQuery {
22
__schema {
3-
queryType {
4-
name
5-
}
6-
mutationType {
7-
name
8-
}
9-
subscriptionType {
10-
name
11-
}
3+
queryType { name kind }
4+
mutationType { name kind }
5+
subscriptionType { name kind }
126
types {
137
...FullType
148
}
159
directives {
1610
name
1711
isRepeatable
1812
locations
19-
args {
13+
args(includeDeprecated: true) {
2014
...InputValue
2115
}
2216
}
2317
}
2418
}
19+
2520
fragment FullType on __Type {
2621
kind
2722
name
28-
specifiedByUrl
23+
specifiedByURL
24+
isOneOf
2925
fields(includeDeprecated: true) {
3026
name
31-
args {
27+
args(includeDeprecated: true) {
3228
...InputValue
3329
}
3430
type {
@@ -37,7 +33,7 @@ fragment FullType on __Type {
3733
isDeprecated
3834
deprecationReason
3935
}
40-
inputFields {
36+
inputFields(includeDeprecated: true) {
4137
...InputValue
4238
}
4339
interfaces {
@@ -52,13 +48,15 @@ fragment FullType on __Type {
5248
...TypeRef
5349
}
5450
}
51+
5552
fragment InputValue on __InputValue {
5653
name
57-
type {
58-
...TypeRef
59-
}
54+
type { ...TypeRef }
6055
defaultValue
56+
isDeprecated
57+
deprecationReason
6158
}
59+
6260
fragment TypeRef on __Type {
6361
kind
6462
name
@@ -83,6 +81,14 @@ fragment TypeRef on __Type {
8381
ofType {
8482
kind
8583
name
84+
ofType {
85+
kind
86+
name
87+
ofType {
88+
kind
89+
name
90+
}
91+
}
8692
}
8793
}
8894
}

juniper/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ where
297297
.await
298298
}
299299

300-
/// Execute the reference introspection query in the provided schema
300+
/// Executes the [canonical introspection query][0] in the provided schema.
301+
///
302+
/// [0]: https://github.com/graphql/graphql-js/blob/v16.11.0/src/utilities/getIntrospectionQuery.ts#L75
301303
pub fn introspect<S, QueryT, MutationT, SubscriptionT>(
302304
root_node: &RootNode<QueryT, MutationT, SubscriptionT, S>,
303305
context: &QueryT::Context,

juniper/src/schema/meta.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ pub struct Argument<S> {
462462
pub arg_type: Type,
463463
#[doc(hidden)]
464464
pub default_value: Option<InputValue<S>>,
465+
#[doc(hidden)]
466+
pub deprecation_status: DeprecationStatus,
465467
}
466468

467469
impl<S> Argument<S> {
@@ -472,6 +474,7 @@ impl<S> Argument<S> {
472474
description: None,
473475
arg_type,
474476
default_value: None,
477+
deprecation_status: DeprecationStatus::Current,
475478
}
476479
}
477480

@@ -499,6 +502,15 @@ impl<S> Argument<S> {
499502
self.default_value = Some(val);
500503
self
501504
}
505+
506+
/// Sets this [`Argument`] as deprecated with an optional `reason`.
507+
///
508+
/// Overwrites any previously set deprecation reason.
509+
#[must_use]
510+
pub fn deprecated(mut self, reason: Option<impl Into<ArcStr>>) -> Self {
511+
self.deprecation_status = DeprecationStatus::Deprecated(reason.map(Into::into));
512+
self
513+
}
502514
}
503515

504516
/// Metadata for a single value in an enum

0 commit comments

Comments
 (0)