Table of Contents
Global ID
Important This is the beginning of a much larger implementation, where pretty much anything would be able to be stored as simple Global IDs.
This gem implements its own version of Rails Global ID. The purpose is to identify GraphQL components within your application uniquely. This feature is widely by request caching and request compiling.
How it Looks Like
"gql://base/Type/String"
"gql://base/Schema/query/welcome"
"gql://base/Directive/deprecated"
"gql://base/Directive/deprecated?reason=Just+because"
The Components
The URI is can be composed of:
- schema
- It will always be gql
- namespace
- Based on the primary namespace of the component, in dash format
- class_name
- The top-most class responsible for the component
- scope?
- For schema fields only, either query,mutation, orsubscription
- name
- The symbolized name of the object
- params?
- A URI-compatible list of parameters
How to Use
You can get the GID of any element by calling .to_global_id.to_s or simply .to_gid.to_s.
Then, you can call GraphQL::GlobalID.find to get the element of a global id.
:001 > GraphQL::AppSchema[:query][:welcome].to_gid.to_s
    => "gql://base/Schema/query/welcome"
:002 > GraphQL::GlobalID.find("gql://base/Schema/query/welcome")
    => #<Rails::GraphQL::Field::OutputField
       #  GraphQL::AppSchema[:query]
       #  welcome: String!>