Skip to content

Commit 4753cf9

Browse files
chore(docs): Update migration guide to add more info about image resolvers (#35105)
Co-authored-by: Lennart <[email protected]>
1 parent cd0b80c commit 4753cf9

File tree

2 files changed

+2
-73
lines changed

2 files changed

+2
-73
lines changed

docs/docs/reference/graphql-data-layer/schema-customization.md

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,76 +1100,3 @@ data.allTeamMember.nodes.map(node => {
11001100
```
11011101

11021102
> Note: All types implementing a queryable interface must also implement the `Node` interface
1103-
1104-
## Extending third-party types
1105-
1106-
So far, the examples have been dealing with types created from locally available data.
1107-
However, Gatsby also allows to integrate and modify third-party GraphQL schemas.
1108-
1109-
Usually, those third-party schemas are retrieved from remote sources via introspection
1110-
query with Gatsby's `gatsby-source-graphql` plugin. To customize types integrated from
1111-
a third-party schema, you can use the [`createResolvers`](/docs/reference/config-files/gatsby-node/#createResolvers) API.
1112-
1113-
### Feeding remote images into `gatsby-image`
1114-
1115-
As an example, you could look at [using-gatsby-source-graphql](https://github.com/gatsbyjs/gatsby/blob/master/examples/using-gatsby-source-graphql/gatsby-node.js) to see how you could use `createResolvers` to feed images from a CMS into `gatsby-image` (the assumption is that `gatsby-source-graphql` was configured
1116-
to prefix all types from the third-party schema with `CMS`):
1117-
1118-
```js:title=gatsby-node.js
1119-
exports.createResolvers = ({
1120-
actions,
1121-
cache,
1122-
createNodeId,
1123-
createResolvers,
1124-
store,
1125-
reporter,
1126-
}) => {
1127-
const { createNode } = actions
1128-
createResolvers({
1129-
CMS_Asset: {
1130-
imageFile: {
1131-
type: `File`,
1132-
resolve(source, args, context, info) {
1133-
return createRemoteFileNode({
1134-
url: source.url,
1135-
store,
1136-
cache,
1137-
createNode,
1138-
createNodeId,
1139-
reporter,
1140-
})
1141-
},
1142-
},
1143-
},
1144-
})
1145-
}
1146-
```
1147-
1148-
You create a new `imageFile` field on the `CMS_Asset` type, which will create `File`
1149-
nodes from every value on the `url` field. Since `File` nodes automatically have
1150-
`childImageSharp` convenience fields available, you can then feed the images from the CMS
1151-
into `gatsby-image` by querying:
1152-
1153-
```graphql
1154-
query {
1155-
cms {
1156-
post {
1157-
# In this example, the `post.image` field is of type `CMS_Asset`
1158-
image {
1159-
# It is important to include all fields in the query which you want to
1160-
# access in the resolver. In this example make sure to include
1161-
# the `url` field. In the future, Gatsby might provide a `@projection`
1162-
# extension to automatically include those fields.
1163-
url
1164-
imageFile {
1165-
childImageSharp {
1166-
fixed {
1167-
...GatsbyImageSharpFixed
1168-
}
1169-
}
1170-
}
1171-
}
1172-
}
1173-
}
1174-
}
1175-
```

docs/docs/reference/release-notes/migrating-from-v3-to-v4.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ The recommended approach is to always create nodes in `sourceNodes`. We are goin
252252
this workaround that will work using `sourceNodes`. It is still being worked on, please post your use-cases and ideas
253253
in [this discussion](https://github.com/gatsbyjs/gatsby/discussions/32860#discussioncomment-1262874) to help us shape this new APIs.
254254

255+
If you've used this with `gatsby-source-graphql`, please switch to [Gatsby GraphQL Source Toolkit](https://github.com/gatsbyjs/gatsby-graphql-toolkit). Generally speaking you'll want to create your own source plugin to fully support such use cases.
256+
255257
You can also learn more about this in the [migration guide for source plugins](/docs/reference/release-notes/migrating-source-plugin-from-v3-to-v4/#2-data-mutations-need-to-happen-during-sourcenodes-or-oncreatenode).
256258

257259
### Changes to built-in types

0 commit comments

Comments
 (0)