GraphQLSwift / GraphQL

The Swift GraphQL implementation for macOS and Linux
MIT License
938 stars 72 forks source link

Crash. Validation not properly works with fragments and then it crashes #28

Closed Igor-Palaguta closed 4 years ago

Igor-Palaguta commented 7 years ago

Added one more type

struct Planet {
    let name: String
    let distance: Int
}

let PlanetType = try! GraphQLObjectType(
    name: "Planet",
    description: "A humanoid creature in the Star Wars universe.",
    fields: [
        "name": GraphQLField(
            type: GraphQLNonNull(GraphQLString),
            description: "The planet name."
        ),
        "distance": GraphQLField(
            type: GraphQLNonNull(GraphQLInt),
            description: "Distance to planet."
        )
    ]
)

Validation test passes, but really should fail. As planet fields are not related to hero

    func testNestedQueryWithFragment() throws {
        let query = "query NestedQueryWithFragment {" +
                    "    hero {" +
                    "        ...PlanetFields" +
                    "    }" +
                    "}" +
                    "fragment PlanetFields on Planet {" +
                    "    name distance" +
                    "}"

        XCTAssert(try validationErrors(query: query).isEmpty)
    }

And during execution such query it crashes here: https://github.com/GraphQLSwift/GraphQL/blob/2ed4f0078f533eb4856a192c30fa78e8d2f1f345/Sources/GraphQL/Execution/Execute.swift#L1161

    // we know this field exists because we passed validation before execution
    return parentType.fields[fieldName]!
paulofaria commented 6 years ago

Can you please check if this issue still occurs with the Swift 4.1 version?

paulofaria commented 6 years ago

that's the version 0.4.0 I just released.

Igor-Palaguta commented 6 years ago

Hello @paulofaria,

Thanks for swift 4.1 support. But this crash is also reproducible in 0.4.0

paulofaria commented 4 years ago

Fixed by the latest release.