编写 以下?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;
}
}
?
?
?
?