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

Avoid casting struct to Hashmap #10

Open
PierreZ opened this issue May 24, 2020 · 0 comments
Open

Avoid casting struct to Hashmap #10

PierreZ opened this issue May 24, 2020 · 0 comments

Comments

@PierreZ
Copy link
Owner

PierreZ commented May 24, 2020

In RecordLayer.java:

        .map(dynamicMessage -> {
          Map<String, Object> results = new HashMap<>();
          dynamicMessage.getAllFields().forEach((key, value) -> results.put(key.getName(), value));
          return results;

We are doing this because:

Once we have a list of ProductDTO objects we typically don’t need specialised data fetchers on each field. graphql-java ships with a smart graphql.schema.PropertyDataFetcher that knows how to follow POJO patterns based on the field name. In the example above there is a name field and hence it will try to look for a public String getName() POJO method to get the data.

https://www.graphql-java.com/documentation/v11/data-fetching/

@PierreZ PierreZ mentioned this issue May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant