Skip to content

Avoid casting struct to Hashmap #10

@PierreZ

Description

@PierreZ

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/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions