directive@rbac("""the user must match all roles""" requireMatchAll: [WG_ROLE]"""the user must match at least one of the roles""" requireMatchAny: [WG_ROLE]"""the user must not match all of the roles""" denyMatchAll: [WG_ROLE]"""the user must not match any of the roles""" denyMatchAny: [WG_ROLE]) onQUERY | MUTATION | SUBSCRIPTIONenumWG_ROLE { admin user}
queryGetOnetodo($uid: Int!@jsonSchema(pattern: "^ [0-9]*$")# 正则表达式校验入参 ) { data: todo_findFirsttodo(where: {user_id: {equals: $uid}}) { id title user_id }}
入参校验指令支持正则表达式,可实现常用的入参合法性校验。
底层定义如下:
directive@jsonSchema(""" The value of both of these keywords MUST be a string. Both of these keywords can be used to decorate a user interface with information about the data produced by this user interface. A title will preferably be short, whereas a description will provide explanation about the purpose of the instance described by this schema. """ title: String""" The value of both of these keywords MUST be a string. Both of these keywords can be used to decorate a user interface with information about the data produced by this user interface. A title will preferably be short, whereas a description will provide explanation about the purpose of the instance described by this schema. """ description: String""" The value of "multipleOf" MUST be a number, strictly greater than 0. A numeric instance is valid only if division by this keyword's value results in an integer. """ multipleOf: Int""" The value of "maximum" MUST be a number, representing an inclusive upper limit for a numeric instance. If the instance is a number, then this keyword validates only if the instance is less than or exactly equal to "maximum". """ maximum: Int""" The value of "exclusiveMaximum" MUST be number, representing an exclusive upper limit for a numeric instance. If the instance is a number, then the instance is valid only if it has a value strictly less than (not equal to) "exclusiveMaximum". """ exclusiveMaximum: Int""" The value of "minimum" MUST be a number, representing an inclusive lower limit for a numeric instance. If the instance is a number, then this keyword validates only if the instance is greater than or exactly equal to "minimum". """ minimum: Int""" The value of "exclusiveMinimum" MUST be number, representing an exclusive lower limit for a numeric instance. If the instance is a number, then the instance is valid only if it has a value strictly greater than (not equal to) "exclusiveMinimum". """ exclusiveMinimum: Int""" The value of this keyword MUST be a non-negative integer. A string instance is valid against this keyword if its length is less than, or equal to, the value of this keyword. The length of a string instance is defined as the number of its characters as defined by RFC 7159 [RFC7159]. """ maxLength: Int""" The value of this keyword MUST be a non-negative integer. A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword. The length of a string instance is defined as the number of its characters as defined by RFC 7159 [RFC7159]. Omitting this keyword has the same behavior as a value of 0. """ minLength: Int""" The value of this keyword MUST be a string. This string SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect. A string instance is considered valid if the regular expression matches the instance successfully. Recall: regular expressions are not implicitly anchored. """ pattern: String""" The value of this keyword MUST be a non-negative integer. An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword. """ maxItems: Int""" The value of this keyword MUST be a non-negative integer. An array instance is valid against "minItems" if its size is greater than, or equal to, the value of this keyword. Omitting this keyword has the same behavior as a value of 0. """ minItems: Int""" The value of this keyword MUST be a boolean. If this keyword has boolean value false, the instance validates successfully. If it has boolean value true, the instance validates successfully if all of its elements are unique. Omitting this keyword has the same behavior as a value of false. """ uniqueItems: Boolean commonPattern: COMMON_REGEX_PATTERN) onVARIABLE_DEFINITIONenumCOMMON_REGEX_PATTERN { EMAIL DOMAIN}
API参数注入
很多场景下,接口的入参需要由服务端动态设置特定参数。飞布内置了如下指令,分别适用不同场景的需求。
@injectGeneratedUUID:生成uuid注入到参数中
@injectCurrentDateTime:获取当前时间,注入到参数中
@injectEnvironmentVariable:获取环境变量,注入到参数中
queryGetOnetodo($uid: Int!@injectGeneratedUUID # 生成UUID) { data: todo_findFirsttodo(where: {user_id: {equals: $uid}}) { id title user_id }}
底层定义如下:
# @injectCurrentDateTime的定义directive@injectCurrentDateTime( format: WunderGraphDateTimeFormat = ISO8601"""customFormat must conform to the Golang specification for specifying a date time format""" customFormat: String) onVARIABLE_DEFINITIONenumWunderGraphDateTimeFormat {"""2006-01-02T15:04:05-0700""" ISO8601"""Mon Jan _2 15:04:05 2006""" ANSIC"""Mon Jan _2 15:04:05 MST 2006""" UnixDate"""Mon Jan 02 15:04:05 -0700 2006""" RubyDate"""02 Jan 06 15:04 MST""" RFC822"""02 Jan 06 15:04 -0700""" RFC822Z"""Monday, 02-Jan-06 15:04:05 MST""" RFC850"""Mon, 02 Jan 2006 15:04:05 MST""" RFC1123"""Mon, 02 Jan 2006 15:04:05 -0700""" RFC1123Z"""2006-01-02T15:04:05Z07:00""" RFC3339"""2006-01-02T15:04:05.999999999Z07:00""" RFC3339Nano"""3:04PM""" Kitchen"""Jan _2 15:04:05""" Stamp"""Jan _2 15:04:05.000""" StampMilli"""Jan _2 15:04:05.000000""" StampMicro"""Jan _2 15:04:05.000000000""" StampNano}# @injectEnvironmentVariable的 定义directive@injectEnvironmentVariable(name: String!) onVARIABLE_DEFINITION