Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fields labeled _ #2769

Merged
merged 4 commits into from
Jan 12, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension String {
enum SwiftKeywords {

static let DisallowedFieldNames: Set<String> = [
"__data", "fragments", "_"
"__data", "fragments"
]

static let DisallowedInputParameterNames: Set<String> = [
Expand Down Expand Up @@ -66,7 +66,8 @@ enum SwiftKeywords {
"Float",
"Double",
"ID",
"Type"
"Type",
"_",
]

/// When an interface or union named "Actor" is used as the type for a field on a test mock,
Expand Down Expand Up @@ -133,6 +134,7 @@ enum SwiftKeywords {
"throws",
"true",
"try",
"_",
]

fileprivate static let InputParameterNamesToEscape: Set<String> = FieldAccessorNamesToEscape
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,12 @@ class InputObjectTemplateTests: XCTestCase {
"try",
type: .nonNull(.string()),
defaultValue: nil
)
),
GraphQLInputField.mock(
"_",
type: .nonNull(.string()),
defaultValue: nil
),
]

buildSubject(fields: fields, config: .mock(schemaName: "TestSchema"))
Expand Down Expand Up @@ -1550,7 +1555,8 @@ class InputObjectTemplateTests: XCTestCase {
`super`: String,
`throws`: String,
`true`: String,
`try`: String
`try`: String,
`_`: String
) {
__data = InputDict([
"associatedtype": `associatedtype`,
Expand Down Expand Up @@ -1602,7 +1608,8 @@ class InputObjectTemplateTests: XCTestCase {
"super": `super`,
"throws": `throws`,
"true": `true`,
"try": `try`
"try": `try`,
"_": `_`
])
}

Expand Down Expand Up @@ -1855,6 +1862,11 @@ class InputObjectTemplateTests: XCTestCase {
get { __data["`try`"] }
set { __data["`try`"] = newValue }
}

public var `_`: String {
get { __data["`_`"] }
set { __data["`_`"] = newValue }
}
"""

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ class SelectionSetTemplateTests: XCTestCase {
protocol: Animal!
type: Animal!
species: String!
_: Animal!
}
"""

Expand Down Expand Up @@ -1029,6 +1030,9 @@ class SelectionSetTemplateTests: XCTestCase {
type {
species
}
_ {
species
}
}
}
"""
Expand All @@ -1051,6 +1055,7 @@ class SelectionSetTemplateTests: XCTestCase {
.field("any", Any_SelectionSet.self),
.field("protocol", Protocol_SelectionSet.self),
.field("type", Type_SelectionSet.self),
.field("_", __SelectionSet.self),
] }
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class DocumentParsingAndValidationTests: XCTestCase {
}

func test__validateDocument__givenFieldNameDisallowed_throwsError() throws {
let disallowedFields = ["__data", "fragments", "Fragments", "_"]
let disallowedFields = ["__data", "fragments", "Fragments"]

for field in disallowedFields {
let schema = try codegenFrontend.loadSchema(
Expand Down