【GraphQL Java】implements,unions 的实现_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 【GraphQL Java】implements,unions 的实现

【GraphQL Java】implements,unions 的实现

 2021/6/14 0:47:04  openxtiger  程序员俱乐部  我要评论(0)
  • 摘要:编写以下GraphQLschema1.定义AppUsageRecord的类型#Storeusageforappsubscriptionswithusagepricing.typeAppUsageRecordimplementsNode{#Thedateandtimewhentheusagerecordwascreated.#createdAt:DateTime!#Thedescriptionoftheappusagerecord.description:String
  • 标签:实现 Union Java Hql

编写 以下?GraphQL schema

1.定义monospace;">AppUsageRecord的类型

?

class="graphql"> # Store usage for app subscriptions with usage pricing.
type AppUsageRecord implements Node {
    # The date and time when the usage record was created.
    # createdAt: DateTime!

    # The description of the app usage record.
    description: String!

    # Globally unique identifier.
    id: ID!

    # The price of the usage record. The only permitted currency code is USD.
    #price: MoneyV2!

    # Defines the usage pricing plan the merchant is subscribed to.
    subscriptionLineItem: AppSubscriptionLineItem!

}

?2. 定义Node接口

?

?

# An object with an ID to support global identification.
interface Node {
    # Globally unique identifier.
    id: ID!
}

?3.相应的Java?AppUsageRecord实现

@Data
//Store usage for app subscriptions with usage pricing.
public class AppUsageRecord implements Node {
    //The date and time when the usage record was created.
    private OffsetDateTime createdAt;

    //The description of the app usage record.
    private String description;

    //Globally unique identifier.
    private String id;

    //The price of the usage record. The only permitted currency code is USD.
    //private MoneyV2 price;

    //Defines the usage pricing plan the merchant is subscribed to.
    private AppSubscriptionLineItem subscriptionLineItem;

}

? 4.相应的Java?Node实现

public interface Node {
    //Globally unique identifier.
    String getId();

    void setId(String id);
}

?5. 如果直接运行,系统将会报错

? ? ?Caused by: graphql.kickstart.tools.SchemaClassScannerError: Object type 'AppUsageRecord' implements a known interface, but no class could be found for that type name.? Please pass a class for type 'AppUsageRecord' in the parser's dictionary.

?

6. 解决方案:

自定义配置AppUsageRecord在parser's dictionary.中

@Configuration
public class GraphQLConfig {
    @Bean
    public SchemaParserDictionary dictionary() {
        SchemaParserDictionary dictionary = new SchemaParserDictionary();
        dictionary.add(AppUsageRecord.class);
        return dictionary;
    }
}

?

?

?

?

发表评论
用户名: 匿名