Skip to content

Get value of input type with custom scalars as Map with already coerced values #424

Open
@ir-dfasen

Description

@ir-dfasen

We have a mutation with an input type that includes custom scalars. We would like to have our mutation resolver being called with the parsed value for the input type as a Map so we are able to see which properties have been set and which not.

scalar A
scalar B

input MyInput {
    a: A
    b: B
}

type Mutation {
    myMutation(input: MyInput): String
}
public class MyResolver implements GraphQLMutationResolver {
    public String myMutation(LinkedHashMap input) {
        if (input.containsKey("a")) {
            // do something
        }
        if (input.containsKey("b")) {
            // do something
        }
    }
}

However if we implement the mutation resolver like this, the map with the parsed custom scalars is passed on to the ObjectMapper in MethodFieldResolver#createDataFetcher and we loose the parsed values for the custom scalars. We currently solve this by retrieving the map with the parsed custom scalars from the DataFetchingEnvironment like this:

public class MyResolver implements GraphQLMutationResolver {
    public String myMutation(LinkedHashMap input, DataFetchingEnvironment environment) {
        input = environment.getArgument("input");

        if (input.containsKey("a")) {
            // do something
        }
        if (input.containsKey("b")) {
            // do something
        }
    }
}

Could the mutation resolver be called with the parsed custom scalars so we do not need to override the input value with the parsed value in the DataFetchingEnvironment? In a way simular to fix #320 - Add support for lists of Scalar field arguments that are already coerced for issue #198 - Input types with custom scalars in method field resolver.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions