GraphQL规范

对IDEA插件GraphQL生成的规范的总结。详细规范文档请参阅GraphQL规范

内置类型

  • ID: 表示唯一标识符,通常用于对象的重取或缓存键。
  • String: 表示文本数据,可读的字符串。
  • Boolean:布尔
  • Float:表示双精度浮点数。
  • Int: 整数

"""
The ID scalar type represents a unique identifier, often used to refetch an object or as key for a cache.
The ID type appears in a JSON response as a String; however, it is not intended to be human-readable.
When expected as an input type, any string (such as "4") or integer (such as 4) input value will be accepted as an ID.
"""
scalar ID

"""
The String scalar type represents textual data, represented as UTF-8 character sequences.
The String type is most often used by GraphQL to represent free-form human-readable text.
"""
scalar String

"""
The Boolean scalar type represents true or false.
"""
scalar Boolean

"""
The Float scalar type represents signed double-precision fractional values as specified by IEEE 754.
"""
scalar Float

"""
The Int scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
"""
scalar Int

内置指令

  • @include: 允许在执行期间条件性地包含字段。
  • @skip: 允许在执行期间条件性地排除字段。
  • @deprecated: 指示某些部分已弃用,并提供原因。
  • @specifiedBy: 提供自定义标量的行为说明的URL。
"""
The @include directive may be provided for fields, fragment spreads, and inline fragments,
and allows for conditional inclusion during execution as described by the if argument.
"""
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT


"""
The @skip directive may be provided for fields, fragment spreads, and inline fragments,
and allows for conditional exclusion during execution as described by the if argument.
"""
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT


"""
The @deprecated directive is used within the type system definition language to indicate deprecated portions of a
GraphQL service's schema, such as deprecated fields, enum values, arguments or input fields.

Deprecations include a reason for why it is deprecated, which is formatted using Markdown syntax (as specified by CommonMark).
"""
directive @deprecated(reason: String = "No longer supported") on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE

"""
The @specifiedBy directive is used within the type system definition language
to provide a URL for specifying the behavior of custom scalar definitions.
"""
directive @specifiedBy(url: String!) on SCALAR

自省

对GraphQL服务的查询,使得客户端可以动态理解和查询GraphQL中定义的类型和结构。


type __QueryIntrospectionMeta {
    __schema: __Schema!
    __type(name: String!): __Type
}

type __TypeNameMeta {
    __typename: String!
}

type __Schema {
    description: String
    types: [__Type!]!
    queryType: __Type!
    mutationType: __Type
    subscriptionType: __Type
    directives: [__Directive!]!
}

type __Type {
    kind: __TypeKind!
    name: String
    description: String

    "OBJECT and INTERFACE only"
    fields(includeDeprecated: Boolean = false): [__Field!]

    "OBJECT only"
    interfaces: [__Type!]

    "INTERFACE and UNION only"
    possibleTypes: [__Type!]

    "ENUM only"
    enumValues(includeDeprecated: Boolean = false): [__EnumValue!]

    "INPUT_OBJECT only"
    inputFields(includeDeprecated: Boolean = false): [__InputValue!]

    "NON_NULL and LIST only"
    ofType: __Type

    "May be non-null for custom SCALAR, otherwise null"
    specifiedByURL: String
}

type __Field {
    name: String!
    description: String
    args(includeDeprecated: Boolean = false): [__InputValue!]!
    type: __Type!
    isDeprecated: Boolean!
    deprecationReason: String
}

type __InputValue {
    name: String!
    description: String
    type: __Type!
    defaultValue: String
    isDeprecated: Boolean!
    deprecationReason: String
}

type __EnumValue {
    name: String!
    description: String
    isDeprecated: Boolean!
    deprecationReason: String
}

enum __TypeKind {
    SCALAR,
    OBJECT,
    INTERFACE,
    UNION,
    ENUM,
    INPUT_OBJECT,
    LIST,
    NON_NULL,
}

type __Directive {
    name: String!
    description: String
    locations: [__DirectiveLocation!]!
    args(includeDeprecated: Boolean = false): [__InputValue!]!
    isRepeatable: Boolean!
}

enum __DirectiveLocation {
    QUERY
    MUTATION
    SUBSCRIPTION
    FIELD
    FRAGMENT_DEFINITION
    FRAGMENT_SPREAD
    INLINE_FRAGMENT
    VARIABLE_DEFINITION
    SCHEMA
    SCALAR
    OBJECT
    FIELD_DEFINITION
    ARGUMENT_DEFINITION
    INTERFACE
    UNION
    ENUM
    ENUM_VALUE
    INPUT_OBJECT
    INPUT_FIELD_DEFINITION
}
GraphQL是一种用于构建API的查询语言和运行时的开发工具。相比于传统的REST架构,GraphQL通过提供更清晰、更高效的数据查询和响应机制,极大地提升了开发人员的效率和灵活性。 学习GraphQL需要掌握以下几个方面。首先,要了解GraphQL的核心概念,比如查询、变异、订阅等,以及它们在数据查询和响应过程中的作用。其次,需要学会使用GraphQL的查询语句来获取、筛选和组合数据,包括字段选择、参数传递和嵌套查询等。此外,还需要熟悉GraphQL Schema语言,它定义了可用字段、类型和操作,以及它们之间的关系。掌握Schema语言对于构建和维护GraphQL API非常重要。 在学习过程中,可以使用一些流行的GraphQL库和框架,如Apollo和Relay,它们提供了丰富的工具和功能来简化GraphQL开发。此外,阅读官方的GraphQL规范和文档,参与社区讨论和实践,也是学习的重要途径。 学会GraphQL后,你可以享受到许多好处。首先,GraphQL提供了更高效、精确的数据查询和响应机制,减少了网络传输的数据量,提高了前端性能。其次,GraphQL允许客户端指定需要的数据,避免了传统REST API中的过度获取或不足获取数据的问题,提升了应用的可扩展性和灵活性。此外,GraphQL还支持实时数据订阅,可以用于构建实时聊天、消息推送等功能。 总而言之,学习GraphQL是现代Web开发中的重要一环,它将大大提升开发人员的效率和应用的功能性。通过掌握核心概念、查询语句和Schema语言,结合流行的库和框架,可以更好地应用GraphQL构建高性能、可扩展的API。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值