Skip to content

Commit cb45688

Browse files
feature: Implements specifiedBy directive
1 parent bd09770 commit cb45688

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

Sources/GraphQL/Type/Definition.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ extension GraphQLNonNull: GraphQLWrapperType {}
169169
public final class GraphQLScalarType {
170170
public let name: String
171171
public let description: String?
172+
public let specifiedByURL: String?
172173
public let kind: TypeKind = .scalar
173174

174175
let serialize: (Any) throws -> Map
@@ -178,13 +179,15 @@ public final class GraphQLScalarType {
178179
public init(
179180
name: String,
180181
description: String? = nil,
182+
specifiedByURL: String? = nil,
181183
serialize: @escaping (Any) throws -> Map,
182184
parseValue: ((Map) throws -> Map)? = nil,
183185
parseLiteral: ((Value) throws -> Map)? = nil
184186
) throws {
185187
try assertValid(name: name)
186188
self.name = name
187189
self.description = description
190+
self.specifiedByURL = specifiedByURL
188191
self.serialize = serialize
189192
self.parseValue = parseValue ?? defaultParseValue
190193
self.parseLiteral = parseLiteral ?? defaultParseLiteral
@@ -218,6 +221,7 @@ extension GraphQLScalarType: Encodable {
218221
private enum CodingKeys: String, CodingKey {
219222
case name
220223
case description
224+
case specifiedByURL
221225
case kind
222226
}
223227
}
@@ -229,6 +233,8 @@ extension GraphQLScalarType: KeySubscriptable {
229233
return name
230234
case CodingKeys.description.rawValue:
231235
return description
236+
case CodingKeys.specifiedByURL.rawValue:
237+
return specifiedByURL
232238
case CodingKeys.kind.rawValue:
233239
return kind
234240
default:

Sources/GraphQL/Type/Directives.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ public let GraphQLDeprecatedDirective = try! GraphQLDirective(
123123
]
124124
)
125125

126+
/**
127+
* Used to provide a URL for specifying the behavior of custom scalar definitions.
128+
*/
129+
public let GraphQLSpecifiedByDirective = try! GraphQLDirective(
130+
name: "specifiedBy",
131+
description: "Exposes a URL that specifies the behavior of this scalar.",
132+
locations: [.scalar],
133+
args: [
134+
"url": GraphQLArgument(
135+
type: GraphQLNonNull(GraphQLString),
136+
description: "The URL that specifies the behavior of this scalar."
137+
),
138+
]
139+
)
140+
126141
/**
127142
* Used to indicate an Input Object is a OneOf Input Object.
128143
*/
@@ -140,5 +155,6 @@ let specifiedDirectives: [GraphQLDirective] = [
140155
GraphQLIncludeDirective,
141156
GraphQLSkipDirective,
142157
GraphQLDeprecatedDirective,
158+
GraphQLSpecifiedByDirective,
143159
GraphQLOneOfDirective,
144160
]

Sources/GraphQL/Type/Introspection.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ let __Type: GraphQLObjectType = try! GraphQLObjectType(
185185
"many kinds of types in GraphQL as represented by the `__TypeKind` enum." +
186186
"\n\nDepending on the kind of a type, certain fields describe " +
187187
"information about that type. Scalar types provide no information " +
188-
"beyond a name and description, while Enum types provide their values. " +
188+
"beyond a name and description and optional `specifiedByURL`, while Enum types provide their values. " +
189189
"Object and Interface types provide the fields they describe. Abstract " +
190190
"types, Union and Interface, provide the Object types possible " +
191191
"at runtime. List and NonNull types compose other types.",
@@ -217,6 +217,7 @@ let __Type: GraphQLObjectType = try! GraphQLObjectType(
217217
),
218218
"name": GraphQLField(type: GraphQLString),
219219
"description": GraphQLField(type: GraphQLString),
220+
"specifiedByURL": GraphQLField(type: GraphQLString),
220221
"fields": GraphQLField(
221222
type: GraphQLList(GraphQLNonNull(__Field)),
222223
args: [

0 commit comments

Comments
 (0)