Skip to content

Commit 46eee82

Browse files
rebased on latest
1 parent 919c6c8 commit 46eee82

File tree

3 files changed

+61
-33
lines changed

3 files changed

+61
-33
lines changed

juniper/src/schema/model.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,15 +662,29 @@ impl<'a, S> TypeType<'a, S> {
662662
}
663663

664664
#[derive(Debug)]
665+
/// Represents a GraphQL directive type, including its name, description, locations, arguments, and repeatability.
665666
pub struct DirectiveType<S> {
667+
/// The name of the directive.
666668
pub name: ArcStr,
669+
/// The description of the directive.
667670
pub description: Option<ArcStr>,
671+
/// The locations where the directive can be used.
668672
pub locations: Vec<DirectiveLocation>,
673+
/// The arguments accepted by the directive.
669674
pub arguments: Vec<Argument<S>>,
675+
/// Whether the directive is repeatable.
670676
pub is_repeatable: bool,
671677
}
672678

673679
impl<S> DirectiveType<S> {
680+
/// Creates a new custom directive type with the given name, locations, arguments, and repeatability.
681+
///
682+
/// # Arguments
683+
///
684+
/// * `name` - The name of the directive.
685+
/// * `locations` - The locations where the directive can be used.
686+
/// * `arguments` - The arguments accepted by the directive.
687+
/// * `is_repeatable` - Whether the directive is repeatable.
674688
pub fn new(
675689
name: impl Into<ArcStr>,
676690
locations: &[DirectiveLocation],
@@ -763,51 +777,76 @@ impl<S> DirectiveType<S> {
763777
)
764778
}
765779

780+
/// Sets the description for the directive type and returns the updated instance.
781+
///
782+
/// # Arguments
783+
///
784+
/// * `description` - The description to set for the directive.
766785
pub fn description(mut self, description: impl Into<ArcStr>) -> Self {
767786
self.description = Some(description.into());
768787
self
769788
}
770789
}
771790

791+
/// Represents the valid locations where a GraphQL directive can be used.
772792
#[derive(Clone, Debug, Display, Eq, GraphQLEnum, PartialEq)]
773793
#[graphql(name = "__DirectiveLocation", internal)]
774794
pub enum DirectiveLocation {
795+
/// Location adjacent to a query operation.
775796
#[display("query")]
776797
Query,
798+
/// Location adjacent to a mutation operation.
777799
#[display("mutation")]
778800
Mutation,
801+
/// Location adjacent to a subscription operation.
779802
#[display("subscription")]
780803
Subscription,
804+
/// Location adjacent to a field.
781805
#[display("field")]
782806
Field,
807+
/// Location adjacent to a fragment definition.
783808
#[display("fragment definition")]
784809
FragmentDefinition,
810+
/// Location adjacent to a fragment spread.
785811
#[display("fragment spread")]
786812
FragmentSpread,
813+
/// Location adjacent to an inline fragment.
787814
#[display("inline fragment")]
788815
InlineFragment,
816+
/// Location adjacent to a variable definition.
789817
#[display("variable definition")]
790818
VariableDefinition,
819+
/// Location adjacent to a schema definition.
791820
#[display("schema")]
792821
Schema,
822+
/// Location adjacent to a scalar definition.
793823
#[display("scalar")]
794824
Scalar,
825+
/// Location adjacent to an object type definition.
795826
#[display("object")]
796827
Object,
828+
/// Location adjacent to a field definition.
797829
#[display("field definition")]
798830
FieldDefinition,
831+
/// Location adjacent to an argument definition.
799832
#[display("argument definition")]
800833
ArgumentDefinition,
834+
/// Location adjacent to an interface definition.
801835
#[display("interface")]
802836
Interface,
837+
/// Location adjacent to a union definition.
803838
#[display("union")]
804839
Union,
840+
/// Location adjacent to an enum definition.
805841
#[display("enum")]
806842
Enum,
843+
/// Location adjacent to an enum value definition.
807844
#[display("enum value")]
808845
EnumValue,
846+
/// Location adjacent to an input object definition.
809847
#[display("input object")]
810848
InputObject,
849+
/// Location adjacent to an input field definition.
811850
#[display("input field definition")]
812851
InputFieldDefinition,
813852
}

juniper/src/schema/translate/graphql_parser.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,14 @@ use crate::{
88
};
99

1010
use graphql_parser::{
11-
query::{Directive as ExternalDirective, Number as ExternalNumber, Type as ExternalType},
1211
schema::{
1312
Definition, DirectiveDefinition as ExternalDirectiveDefinition,
14-
DirectiveLocation as ExternalDirectiveLocation, Document, EnumType as ExternalEnum,
15-
EnumValue as ExternalEnumValue, Field as ExternalField,
16-
InputObjectType as ExternalInputObjectType, InputValue as ExternalInputValue,
17-
InterfaceType as ExternalInterfaceType, ObjectType as ExternalObjectType,
18-
ScalarType as ExternalScalarType, SchemaDefinition, Text,
19-
TypeDefinition as ExternalTypeDefinition, UnionType as ExternalUnionType,
20-
Value as ExternalValue,
13+
DirectiveLocation as ExternalDirectiveLocation,
2114
},
2215
};
2316

2417
use crate::{
2518
DirectiveLocation,
26-
ast::{InputValue, Type},
27-
schema::{
28-
meta::{Argument, DeprecationStatus, EnumValue, Field, MetaType},
29-
},
3019
value::ScalarValue,
3120
};
3221

@@ -114,7 +103,7 @@ impl GraphQLParserTranslator {
114103
fn translate_location<'a, S, T>(location: &DirectiveLocation) -> ExternalDirectiveLocation
115104
where
116105
S: ScalarValue,
117-
T: Text<'a>,
106+
T: schema::Text<'a>,
118107
{
119108
match location {
120109
DirectiveLocation::Query => ExternalDirectiveLocation::Query,

juniper/src/tests/schema_introspection.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(crate) fn schema_introspection_result() -> Value {
4242
{
4343
"kind": "ENUM",
4444
"name": "__DirectiveLocation",
45-
"description": null,
45+
"description": "Represents the valid locations where a GraphQL directive can be used.",
4646
"specifiedByURL": null,
4747
"isOneOf": null,
4848
"fields": null,
@@ -51,115 +51,115 @@ pub(crate) fn schema_introspection_result() -> Value {
5151
"enumValues": [
5252
{
5353
"name": "QUERY",
54-
"description": null,
54+
"description": "Location adjacent to a query operation.",
5555
"isDeprecated": false,
5656
"deprecationReason": null
5757
},
5858
{
5959
"name": "MUTATION",
60-
"description": null,
60+
"description": "Location adjacent to a mutation operation.",
6161
"isDeprecated": false,
6262
"deprecationReason": null
6363
},
6464
{
6565
"name": "SUBSCRIPTION",
66-
"description": null,
66+
"description": "Location adjacent to a subscription operation.",
6767
"isDeprecated": false,
6868
"deprecationReason": null
6969
},
7070
{
7171
"name": "FIELD",
72-
"description": null,
72+
"description": "Location adjacent to a field.",
7373
"isDeprecated": false,
7474
"deprecationReason": null
7575
},
7676
{
7777
"name": "FRAGMENT_DEFINITION",
78-
"description": null,
78+
"description": "Location adjacent to a fragment definition.",
7979
"isDeprecated": false,
8080
"deprecationReason": null
8181
},
8282
{
8383
"name": "FRAGMENT_SPREAD",
84-
"description": null,
84+
"description": "Location adjacent to a fragment spread.",
8585
"isDeprecated": false,
8686
"deprecationReason": null
8787
},
8888
{
8989
"name": "INLINE_FRAGMENT",
90-
"description": null,
90+
"description": "Location adjacent to an inline fragment.",
9191
"isDeprecated": false,
9292
"deprecationReason": null
9393
},
9494
{
9595
"name": "VARIABLE_DEFINITION",
96-
"description": null,
96+
"description": "Location adjacent to a variable definition.",
9797
"isDeprecated": false,
9898
"deprecationReason": null
9999
},
100100
{
101101
"name": "SCHEMA",
102-
"description": null,
102+
"description": "Location adjacent to a schema definition.",
103103
"isDeprecated": false,
104104
"deprecationReason": null
105105
},
106106
{
107107
"name": "SCALAR",
108-
"description": null,
108+
"description": "Location adjacent to a scalar definition.",
109109
"isDeprecated": false,
110110
"deprecationReason": null
111111
},
112112
{
113113
"name": "OBJECT",
114-
"description": null,
114+
"description": "Location adjacent to an object type definition.",
115115
"isDeprecated": false,
116116
"deprecationReason": null
117117
},
118118
{
119119
"name": "FIELD_DEFINITION",
120-
"description": null,
120+
"description": "Location adjacent to a field definition.",
121121
"isDeprecated": false,
122122
"deprecationReason": null
123123
},
124124
{
125125
"name": "ARGUMENT_DEFINITION",
126-
"description": null,
126+
"description": "Location adjacent to an argument definition.",
127127
"isDeprecated": false,
128128
"deprecationReason": null
129129
},
130130
{
131131
"name": "INTERFACE",
132-
"description": null,
132+
"description": "Location adjacent to an interface definition.",
133133
"isDeprecated": false,
134134
"deprecationReason": null
135135
},
136136
{
137137
"name": "UNION",
138-
"description": null,
138+
"description": "Location adjacent to a union definition.",
139139
"isDeprecated": false,
140140
"deprecationReason": null
141141
},
142142
{
143143
"name": "ENUM",
144-
"description": null,
144+
"description": "Location adjacent to an enum definition.",
145145
"isDeprecated": false,
146146
"deprecationReason": null
147147
},
148148
{
149149
"name": "ENUM_VALUE",
150-
"description": null,
150+
"description": "Location adjacent to an enum value definition.",
151151
"isDeprecated": false,
152152
"deprecationReason": null
153153
},
154154
{
155155
"name": "INPUT_OBJECT",
156-
"description": null,
156+
"description": "Location adjacent to an input object definition.",
157157
"isDeprecated": false,
158158
"deprecationReason": null
159159
},
160160
{
161161
"name": "INPUT_FIELD_DEFINITION",
162-
"description": null,
162+
"description": "Location adjacent to an input field definition.",
163163
"isDeprecated": false,
164164
"deprecationReason": null
165165
}

0 commit comments

Comments
 (0)