How to expose graphql field with different name

后端 未结 4 1496
攒了一身酷
攒了一身酷 2020-12-18 18:33

I am exploring GraphQL and would like to know if there is any way of renaming the response field for example i have a POJO with these field

class POJO {
  Lo         


        
4条回答
  •  再見小時候
    2020-12-18 18:51

    The question is: how are you creating the schema in the first place? There's no intrinsic connection between Java and GraphQL types - they are completely unrelated unless you correlate them. So you can name the fields any way you want in the schema, and make a resolver (DataFetcher) that gets the value from anywhere (thus any POJO field too).

    If you're using a tool to generate the schema from Java types (graphql-java-annotations, graphql-spqr etc), then use that tool's facilities to drive the mapping. Both the mentioned tools allow customizing the mapping via annotations. GraphQL-SPQR enables the same via external configuration as well.

    If you clarify your question further, I'll be able to give a more precise answer.

提交回复
热议问题