gpt4 book ai didi

javascript - Gatsby 查询类型未显示在 graphiQl 中

转载 作者:行者123 更新时间:2023-11-30 13:46:03 24 4
gpt4 key购买 nike

我正在创建一个 gatsby 插件。在开发中我没有收到任何错误或警告,但我在 graphiql 中看不到我的查询(或在 http://localhost:8000/___graphql )

module.exports = {
siteMetadata: {
title: `Gatsby Default Starter`,
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
author: `@gatsbyjs`,
},
plugins: [
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `gatsby-starter-default`,
short_name: `starter`,
start_url: `/`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
},
},
{
resolve: 'gatsby-source-custom',
options: {
workspaceId: 'spaceyfi-dummy',
schemaId: 'custom-development'
}
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// `gatsby-plugin-offline`,
],
}

这是我在根目录下的插件文件夹结构

在文件夹内,index.js 为空文件 enter image description here

getsby-node.js 看起来像这样

 const selfSdk = require('selfSdk')

function createNodeContent (data, id, type) {
const nodeId = createNodeId(id)
const nodeContent = JSON.stringify(data)
const contentDigest = createContentDigest(data)
const nodeMeta = {
id: nodeId,
parent: null,
children: [],
internal: {
type: type, // used to generate the resulting GraphQL query name
content: nodeContent,
contentDigest
}
}
const node = Object.assign({}, data, nodeMeta)
return node
}

exports.sourceNodes = async ({ actions, createNodeId, createContentDigest }, {
workspaceId,
schemaId
}) => {
const { createNode, setPluginStatus } = actions
const workspace = selfSdk.getWorkspace(workspaceId)
console.log(workspaceId, schemaId)
// If there is schemaId but we don't have itemId, load all posts
try {
const itemsList = await workspace.read(schemaId)
const type = `getPosts`
itemsList.forEach(({data, id}) => {
createNode(createNodeContent(data, id, type))
})


} catch (error) {
console.error(`Error Fetching data`)
console.error(error)
}
setPluginStatus({
status: {
lastFetched: Date.now()
}
})
}

这是我的 grphiql

enter image description here

最佳答案

Gatsby 将在您的插件文件夹的根目录中寻找 gatsby-node.js

plugins/
– your-plugin/
-- gatsby-node.js
-- package.json

https://www.gatsbyjs.org/docs/files-gatsby-looks-for-in-a-plugin/

https://www.gatsbyjs.org/docs/creating-a-source-plugin/#what-does-the-code-look-like

这就是它没有出现在您的 GraphiQL 中的原因。您的插件不会生成任何节点,因为您有一个空白的 index.js,所以它看起来像是一个不导出任何内容的模块。

关于javascript - Gatsby 查询类型未显示在 graphiQl 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59317501/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com