Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding nodes to Magento schema #477

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions design-documents/graph-ql/coverage/nodes.graphqls
Original file line number Diff line number Diff line change
@@ -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 {
}
39 changes: 39 additions & 0 deletions design-documents/graph-ql/nodes.md
Original file line number Diff line number Diff line change
@@ -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)