Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 62 additions & 27 deletions Sources/GraphQL/Language/AST.swift
Original file line number Diff line number Diff line change
Expand Up @@ -811,16 +811,18 @@ public final class StringValue {
public let kind: Kind = .stringValue
public let loc: Location?
public let value: String
public let block: Bool?

init(loc: Location? = nil, value: String) {
init(loc: Location? = nil, value: String, block: Bool? = nil) {
self.loc = loc
self.value = value
self.block = block
}
}

extension StringValue : Equatable {
public static func == (lhs: StringValue, rhs: StringValue) -> Bool {
return lhs.value == rhs.value
return lhs.value == rhs.value && lhs.block == rhs.block
}
}

Expand Down Expand Up @@ -1076,20 +1078,23 @@ public func == (lhs: TypeSystemDefinition, rhs: TypeSystemDefinition) -> Bool {
public final class SchemaDefinition {
public let kind: Kind = .schemaDefinition
public let loc: Location?
public let description: StringValue?
public let directives: [Directive]
public let operationTypes: [OperationTypeDefinition]

init(loc: Location? = nil, directives: [Directive], operationTypes: [OperationTypeDefinition]) {
init(loc: Location? = nil, description: StringValue? = nil, directives: [Directive], operationTypes: [OperationTypeDefinition]) {
self.loc = loc
self.description = description
self.directives = directives
self.operationTypes = operationTypes
}
}

extension SchemaDefinition : Equatable {
public static func == (lhs: SchemaDefinition, rhs: SchemaDefinition) -> Bool {
return lhs.directives == rhs.directives &&
lhs.operationTypes == rhs.operationTypes
return lhs.description == rhs.description &&
lhs.directives == rhs.directives &&
lhs.operationTypes == rhs.operationTypes
}
}

Expand Down Expand Up @@ -1157,33 +1162,38 @@ public func == (lhs: TypeDefinition, rhs: TypeDefinition) -> Bool {
public final class ScalarTypeDefinition {
public let kind: Kind = .scalarTypeDefinition
public let loc: Location?
public let description: StringValue?
public let name: Name
public let directives: [Directive]

init(loc: Location? = nil, name: Name, directives: [Directive] = []) {
init(loc: Location? = nil, description: StringValue? = nil, name: Name, directives: [Directive] = []) {
self.loc = loc
self.description = description
self.name = name
self.directives = directives
}
}

extension ScalarTypeDefinition : Equatable {
public static func == (lhs: ScalarTypeDefinition, rhs: ScalarTypeDefinition) -> Bool {
return lhs.name == rhs.name &&
return lhs.description == rhs.description &&
lhs.name == rhs.name &&
lhs.directives == rhs.directives
}
}

public final class ObjectTypeDefinition {
public let kind: Kind = .objectTypeDefinition
public let loc: Location?
public let description: StringValue?
public let name: Name
public let interfaces: [NamedType]
public let directives: [Directive]
public let fields: [FieldDefinition]

init(loc: Location? = nil, name: Name, interfaces: [NamedType] = [], directives: [Directive] = [], fields: [FieldDefinition] = []) {
init(loc: Location? = nil, description: StringValue? = nil, name: Name, interfaces: [NamedType] = [], directives: [Directive] = [], fields: [FieldDefinition] = []) {
self.loc = loc
self.description = description
self.name = name
self.interfaces = interfaces
self.directives = directives
Expand All @@ -1193,7 +1203,8 @@ public final class ObjectTypeDefinition {

extension ObjectTypeDefinition : Equatable {
public static func == (lhs: ObjectTypeDefinition, rhs: ObjectTypeDefinition) -> Bool {
return lhs.name == rhs.name &&
return lhs.description == rhs.description &&
lhs.name == rhs.name &&
lhs.interfaces == rhs.interfaces &&
lhs.directives == rhs.directives &&
lhs.fields == rhs.fields
Expand All @@ -1203,13 +1214,15 @@ extension ObjectTypeDefinition : Equatable {
public final class FieldDefinition {
public let kind: Kind = .fieldDefinition
public let loc: Location?
public let description: StringValue?
public let name: Name
public let arguments: [InputValueDefinition]
public let type: Type
public let directives: [Directive]

init(loc: Location? = nil, name: Name, arguments: [InputValueDefinition] = [], type: Type, directives: [Directive] = []) {
init(loc: Location? = nil, description: StringValue? = nil, name: Name, arguments: [InputValueDefinition] = [], type: Type, directives: [Directive] = []) {
self.loc = loc
self.description = description
self.name = name
self.arguments = arguments
self.type = type
Expand All @@ -1219,7 +1232,8 @@ public final class FieldDefinition {

extension FieldDefinition : Equatable {
public static func == (lhs: FieldDefinition, rhs: FieldDefinition) -> Bool {
return lhs.name == rhs.name &&
return lhs.description == rhs.description &&
lhs.name == rhs.name &&
lhs.arguments == rhs.arguments &&
lhs.type == rhs.type &&
lhs.directives == rhs.directives
Expand All @@ -1229,13 +1243,15 @@ extension FieldDefinition : Equatable {
public final class InputValueDefinition {
public let kind: Kind = .inputValueDefinition
public let loc: Location?
public let description: StringValue?
public let name: Name
public let type: Type
public let defaultValue: Value?
public let directives: [Directive]

init(loc: Location? = nil, name: Name, type: Type, defaultValue: Value? = nil, directives: [Directive] = []) {
init(loc: Location? = nil, description: StringValue? = nil, name: Name, type: Type, defaultValue: Value? = nil, directives: [Directive] = []) {
self.loc = loc
self.description = description
self.name = name
self.type = type
self.defaultValue = defaultValue
Expand Down Expand Up @@ -1272,19 +1288,22 @@ extension InputValueDefinition : Equatable {
public final class InterfaceTypeDefinition {
public let kind: Kind = .interfaceTypeDefinition
public let loc: Location?
public let description: StringValue?
public let name: Name
public let interfaces: [NamedType]
public let directives: [Directive]
public let fields: [FieldDefinition]

init(
loc: Location? = nil,
description: StringValue? = nil,
name: Name,
interfaces: [NamedType] = [],
directives: [Directive] = [],
fields: [FieldDefinition]
) {
self.loc = loc
self.description = description
self.name = name
self.interfaces = interfaces
self.directives = directives
Expand All @@ -1294,7 +1313,8 @@ public final class InterfaceTypeDefinition {

extension InterfaceTypeDefinition : Equatable {
public static func == (lhs: InterfaceTypeDefinition, rhs: InterfaceTypeDefinition) -> Bool {
return lhs.name == rhs.name &&
return lhs.description == rhs.description &&
lhs.name == rhs.name &&
lhs.directives == rhs.directives &&
lhs.fields == rhs.fields
}
Expand All @@ -1303,12 +1323,14 @@ extension InterfaceTypeDefinition : Equatable {
public final class UnionTypeDefinition {
public let kind: Kind = .unionTypeDefinition
public let loc: Location?
public let description: StringValue?
public let name: Name
public let directives: [Directive]
public let types: [NamedType]

init(loc: Location? = nil, name: Name, directives: [Directive] = [], types: [NamedType]) {
init(loc: Location? = nil, description: StringValue? = nil, name: Name, directives: [Directive] = [], types: [NamedType]) {
self.loc = loc
self.description = description
self.name = name
self.directives = directives
self.types = types
Expand All @@ -1317,7 +1339,8 @@ public final class UnionTypeDefinition {

extension UnionTypeDefinition : Equatable {
public static func == (lhs: UnionTypeDefinition, rhs: UnionTypeDefinition) -> Bool {
return lhs.name == rhs.name &&
return lhs.description == rhs.description &&
lhs.name == rhs.name &&
lhs.directives == rhs.directives &&
lhs.types == rhs.types
}
Expand All @@ -1326,12 +1349,14 @@ extension UnionTypeDefinition : Equatable {
public final class EnumTypeDefinition {
public let kind: Kind = .enumTypeDefinition
public let loc: Location?
public let description: StringValue?
public let name: Name
public let directives: [Directive]
public let values: [EnumValueDefinition]

init(loc: Location? = nil, name: Name, directives: [Directive] = [], values: [EnumValueDefinition]) {
init(loc: Location? = nil, description: StringValue? = nil, name: Name, directives: [Directive] = [], values: [EnumValueDefinition]) {
self.loc = loc
self.description = description
self.name = name
self.directives = directives
self.values = values
Expand All @@ -1340,7 +1365,8 @@ public final class EnumTypeDefinition {

extension EnumTypeDefinition : Equatable {
public static func == (lhs: EnumTypeDefinition, rhs: EnumTypeDefinition) -> Bool {
return lhs.name == rhs.name &&
return lhs.description == rhs.description &&
lhs.name == rhs.name &&
lhs.directives == rhs.directives &&
lhs.values == rhs.values
}
Expand All @@ -1349,32 +1375,37 @@ extension EnumTypeDefinition : Equatable {
public final class EnumValueDefinition {
public let kind: Kind = .enumValueDefinition
public let loc: Location?
public let description: StringValue?
public let name: Name
public let directives: [Directive]

init(loc: Location? = nil, name: Name, directives: [Directive] = []) {
init(loc: Location? = nil, description: StringValue? = nil, name: Name, directives: [Directive] = []) {
self.loc = loc
self.description = description
self.name = name
self.directives = directives
}
}

extension EnumValueDefinition : Equatable {
public static func == (lhs: EnumValueDefinition, rhs: EnumValueDefinition) -> Bool {
return lhs.name == rhs.name &&
return lhs.description == rhs.description &&
lhs.name == rhs.name &&
lhs.directives == rhs.directives
}
}

public final class InputObjectTypeDefinition {
public let kind: Kind = .inputObjectTypeDefinition
public let loc: Location?
public let description: StringValue?
public let name: Name
public let directives: [Directive]
public let fields: [InputValueDefinition]

init(loc: Location? = nil, name: Name, directives: [Directive] = [], fields: [InputValueDefinition]) {
init(loc: Location? = nil, description: StringValue? = nil, name: Name, directives: [Directive] = [], fields: [InputValueDefinition]) {
self.loc = loc
self.description = description
self.name = name
self.directives = directives
self.fields = fields
Expand All @@ -1383,9 +1414,10 @@ public final class InputObjectTypeDefinition {

extension InputObjectTypeDefinition : Equatable {
public static func == (lhs: InputObjectTypeDefinition, rhs: InputObjectTypeDefinition) -> Bool {
return lhs.name == rhs.name &&
lhs.directives == rhs.directives &&
lhs.fields == rhs.fields
return lhs.description == rhs.description &&
lhs.name == rhs.name &&
lhs.directives == rhs.directives &&
lhs.fields == rhs.fields
}
}

Expand All @@ -1409,22 +1441,25 @@ extension TypeExtensionDefinition : Equatable {
public final class DirectiveDefinition {
public let kind: Kind = .directiveDefinition
public let loc: Location?
public let description: StringValue?
public let name: Name
public let arguments: [InputValueDefinition]
public let locations: [Name]

init(loc: Location? = nil, name: Name, arguments: [InputValueDefinition] = [], locations: [Name]) {
init(loc: Location? = nil, description: StringValue? = nil, name: Name, arguments: [InputValueDefinition] = [], locations: [Name]) {
self.loc = loc
self.name = name
self.description = description
self.arguments = arguments
self.locations = locations
}
}

extension DirectiveDefinition : Equatable {
public static func == (lhs: DirectiveDefinition, rhs: DirectiveDefinition) -> Bool {
return lhs.name == rhs.name &&
lhs.arguments == rhs.arguments &&
lhs.locations == rhs.locations
return lhs.description == rhs.description &&
lhs.name == rhs.name &&
lhs.arguments == rhs.arguments &&
lhs.locations == rhs.locations
}
}
27 changes: 27 additions & 0 deletions Sources/GraphQL/Language/Lexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,33 @@ final class Lexer {
func advance() throws -> Token {
return try advanceFunction(self)
}

/**
* Looks ahead and returns the next non-ignored token, but does not change
* the state of Lexer.
*/
func lookahead() throws -> Token {
var startToken = token
let savedLine = self.line
let savedLineStart = self.lineStart

guard startToken.kind != .eof else { return startToken }
repeat {
startToken = try startToken.next ??
{
startToken.next = try readToken(lexer: self, prev: startToken)
return startToken.next!
}()
} while startToken.kind == .comment

// restore these since both `positionAfterWhitespace` & `readBlockString`
// can potentially modify them and commment for `lookahead` says no lexer modification.
// (the latter is true in the canonical js lexer also and is likely a bug)
self.line = savedLine
self.lineStart = savedLineStart

return startToken
}
}

/**
Expand Down
Loading