-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parsing of input objects as default values for input params (#3074)
Co-authored-by: Zach FettersMoore <[email protected]>
- Loading branch information
1 parent
ff49bec
commit 077430a
Showing
4 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
Tests/ApolloCodegenTests/CodeGenIR/IRInputObjectTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Foundation | ||
import XCTest | ||
import Nimble | ||
import OrderedCollections | ||
@testable import ApolloCodegenLib | ||
|
||
class IRInputObjectTests: XCTestCase { | ||
|
||
var subject: GraphQLInputObjectType! | ||
var schemaSDL: String! | ||
var document: String! | ||
|
||
override func tearDown() { | ||
subject = nil | ||
schemaSDL = nil | ||
document = nil | ||
|
||
super.tearDown() | ||
} | ||
|
||
// MARK: - Helpers | ||
|
||
func buildSubject() throws { | ||
let ir: IR = try .mock(schema: schemaSDL, document: document) | ||
subject = ir.schema.referencedTypes.inputObjects.first! | ||
} | ||
|
||
// MARK: - Tests | ||
|
||
func test__compileInputObject__givenNestedInputObjectParameterWithDefaultValue_compilesInputTypeWithDefaultValue() throws { | ||
// given | ||
schemaSDL = """ | ||
type Query { | ||
exampleQuery(input: Input!): String! | ||
} | ||
input ChildInput { | ||
a: String | ||
b: String | ||
c: String | ||
} | ||
input Input { | ||
child: ChildInput = { a: "a", b: "b", c: "c" } | ||
} | ||
""" | ||
|
||
document = """ | ||
query TestOperation($input: Input!) { | ||
exampleQuery(input: $input) | ||
} | ||
""" | ||
|
||
// when | ||
try buildSubject() | ||
let childField = subject.fields["child"] | ||
|
||
let expectedDefaultValue = GraphQLValue.object([ | ||
"a": .string("a"), | ||
"b": .string("b"), | ||
"c": .string("c") | ||
]) | ||
|
||
// then | ||
expect(childField?.defaultValue).to(equal(expectedDefaultValue)) | ||
} | ||
|
||
} |