Skip to content

Commit

Permalink
enhancement(docs): Add documentation on the @Childof and @mimetypes e…
Browse files Browse the repository at this point in the history
…xtensions (#25461)

* Add documenation on the @Childof and @mimetypes extensions

* PR comments
  • Loading branch information
tesseralis committed Jul 9, 2020
1 parent acce507 commit 32d9578
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions docs/docs/schema-customization.md
Expand Up @@ -209,6 +209,66 @@ Note that you don't need to explicitly provide the Node interface fields (`id`,
> [specifying nullability](https://graphql.org/learn/schema/#lists-and-non-null)
> in GraphQL, i.e. if a field value is allowed to be `null` or not.
#### Defining media types

You can specify the media types handled by a node type using the `@mimeTypes` extension:

```graphql
type Markdown implements Node
@mimeTypes(types: ["text/markdown", "text/x-markdown"]) {
id: ID!
}
```

The types passed in are used to determine child relations of the node.

#### Defining child relations

The `@childOf` extension can be used to explicitly define what node types or media types a node is a child of and immediately add `child[MyType]` or `children[MyType]` as a field on the parent.

The `types` argument takes an array of strings and determines what node types the node is a child of:

```graphql
# Adds `childMdx` as a field of `File` and `Markdown` nodes
type Mdx implements Node @childOf(types: ["File", "Markdown"]) {
id: ID!
}
```

The `mimeTypes` argument takes an array of strings and determines what media types the node is a child of:

```graphql
# Adds `childMdx` as a child of any node type with the `@mimeTypes` set to "text/markdown" or "text/x-markdown"
type Mdx implements Node
@childOf(mimeTypes: ["text/markdown", "text/x-markdown"]) {
id: ID!
}
```

The `mimeTypes` and `types` arguments can be combined as follows:

```graphql
# Adds `childMdx` as a child to `File` nodes *and* nodes with `@mimeTypes` set to "text/markdown" or "text/x-markdown"
type Mdx implements Node
@childOf(types: ["File"], mimeTypes: ["text/markdown", "text/x-markdown"]) {
id: ID!
}
```

If `many: true` is set, then instead of creating a single child field on the parent, it will create multiple:

```graphql
# Adds `childMdx1` with type `Mdx1` to `File`.
type Mdx1 implements Node @childOf(types: ["File"]) {
id: ID!
}

# Adds `childrenMdx2` with type `[Mdx2]` as a field of `File`.
type Mdx2 implements Node @childOf(types: ["File"], many: true) {
id: ID!
}
```

#### Nested types

So far, the example project has only been dealing with scalar values (`String` and `Date`;
Expand Down

0 comments on commit 32d9578

Please sign in to comment.