diff --git a/design-documents/graph-ql/coverage/nodes.graphqls b/design-documents/graph-ql/coverage/nodes.graphqls new file mode 100644 index 000000000..f0ac60396 --- /dev/null +++ b/design-documents/graph-ql/coverage/nodes.graphqls @@ -0,0 +1,41 @@ +type Query { + #initially we have to still support numeric ids + node(id: Int & uid: ID): Node +} + +interface NodeInterface { + uid: ID! @doc(description: "The unique ID for a `Node") +} + +type Node implements NodeInterface { + # inherits uid: ID! @doc(description: "The unique ID for a `Node") +} + +#adding to every product type a node interface +type SimpleProduct implements ProductInterface & NodeInterface & PhysicalProductInterface & CustomizableProductInterface { +} + +type VirtualProduct implements ProductInterface & NodeInterface & CustomizableProductInterface { +} + +#adding to every product type a node interface & also look for additional modules +type ConfigurableProduct implements ProductInterface & NodeInterface & PhysicalProductInterface & CustomizableProductInterface { +} + +type BundleProduct implements ProductInterface & NodeInterface & PhysicalProductInterface & CustomizableProductInterface { +} + +type DownloadableProduct implements ProductInterface & NodeInterface & CustomizableProductInterface { +} + +type GroupedProduct implements ProductInterface & NodeInterface & PhysicalProductInterface { +} + +type GiftCardProduct implements ProductInterface & PhysicalProductInterface & CustomizableProductInterface { +} + +type CategoryTree implements CategoryInterface & NodeInterface { +} + +type CmsPage implements NodeInterface { +} diff --git a/design-documents/graph-ql/nodes.md b/design-documents/graph-ql/nodes.md new file mode 100644 index 000000000..2fbb825f0 --- /dev/null +++ b/design-documents/graph-ql/nodes.md @@ -0,0 +1,39 @@ +# GraphQL Nodes - Global Object Identification + +To provide options for GraphQL clients to elegantly handle caching and data refetching, GraphQL servers need to expose object identifiers in a standardized way. + +For this to work, a client will need to query via a standard mechanism to request an object by ID. Then, in the response, the schema will need to provide a standard way of providing these IDs. + +Example +```graphql +{ + node(uid: "MTM0MzQ=") { + id + ... on SimpleProduct { + name + uid + } + ... on CategoryTree { + name + children + } + } +} +``` + +Nodes IDs should be unique throughout the entire schema and ideally for every store since store code is unique + +To implement this the uid has to be composed out of: +``` +base64Encode("StoreCode/__typeName/id") +``` + +This way we can know what is the type requested and render it to the actual type. +It will help our schema to be more compliant as all entities should be nodes. + +More information in the Graphql Spec +- [https://graphql.org/learn/global-object-identification/](https://graphql.org/learn/global-object-identification/) + + +Schema implementation +- [nodes.graphqls](coverage/nodes.graphqls)