★ wanayoo — archive 1999 https://github.com/graphql-java-kickstart/graphql-java-tools/issues/424Nouvelle recherche | Portail wanayoo
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

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

Open
ir-dfasen opened this issue Aug 6, 2020 · 0 comments

Comments

@ir-dfasen
Copy link

@ir-dfasen ir-dfasen commented Aug 6, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.