在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):graphql-java/graphql-java-extended-scalars开源软件地址(OpenSource Url):https://github.com/graphql-java/graphql-java-extended-scalars开源编程语言(OpenSource Language):Java 54.9%开源软件介绍(OpenSource Introduction):Extended Scalars for graphql-javaThis library provides extended scalars for graphql-java Scalars in graphql are the leaf nodes of a query, the non-compound values that can't be queried further via sub-field selections. The graphql standard specifies that the You would use custom scalars when you want to describe more meaningful behavior or ranges of values. To use this library put the following into your gradle config
or the following into your Maven config
It's currently available from Maven Central. Then register the scalar with graphql-java
And use it in your schema
DateTime Scalars
See the rfc3339 spec for more details on the format. An example declaration in SDL might be: type Customer {
birthDay : Date
workStartTime : Time
bornAt : DateTime
}
type Query {
customers(bornAfter : DateTime) : [Customers]
}
And example query might look like:
query {
customers(bornAfter : "1996-12-19T16:39:57-08:00") {
birthDay
bornAt
}
}
ID Scalars
Object / JSON Scalars
One of the design goals of graphql, is that the type system describes the shape of the data returned. The An example might be an extensible graphql system where systems can input custom metadata objects that cant be known at schema type design time. An example declaration in SDL might be: type Customer {
name : String
associatedMetaData : JSON
}
type Query {
customers(filterSyntax : JSON) : [Customers]
}
And example query might look like:
query {
customers(filterSyntax : {
startSpan : "First",
matchCriteria : {
countryCode : "AU",
isoCodes : ["27B-34R", "95A-E23"],
}
}) {
name
associatedMetaData
}
}
Note : The Numeric Scalars
The numeric scalars are derivations of the standard graphql An example declaration in SDL might be: type Customer {
name : String
currentHeight : PositiveInt
weightLossGoal : NonPositiveInt
averageWeightLoss : NegativeFloat
}
type Query {
customers(height : PositiveInt) : [Customers]
}
And example query might look like:
query {
customers(height : 182) {
name
height
weightLossGoal
}
}
Regex ScalarsThe RegexScalar has a builder where you provide one or more regex patterns that control the acceptable values for a new scalar. You name the scalar and it provides an implementation. For example, imagine a RegexScalar phoneNumberScalar = ExtendedScalars.newRegexScalar("phoneNumber")
.addPattern(Pattern.compile("\\([0-9]*\\)[0-9]*"))
.build() Locale ScalarThe Locale scalar handles IETF BCP 47 language tags via the JDK method Locale.forLanguageTag type Customer {
name : String
locale : Locale
}
type Query {
customers(inLocale : Locale) : [Customers]
} An example query to look for customers in the Romanian locale might look like:
query {
customers(inLocale : "ro-RO") {
name
locale
}
}
Alias ScalarsYou can create aliases for existing scalars to add more semantic meaning to them. For example a link to a social media post could be representing by a For example, you would build it like this: AliasedScalar socialMediaLink = ExtendedScalars.newAliasedScalar("SocialMediaLink")
.aliasedScalar(Scalars.GraphQLString)
.build() And use it in a SDL schema like this : type Customer {
name : String
socialMediaLink : SocialMediaLink
}
Note: A future version of the graphql specification may add this capability but in the meantime you can use this facility. Java Primitives
Other Scalars
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论