sta*_*ane 4 reactjs graphql graphql-js jupyter-notebook gatsby
我正在尝试向gatsby-starter-hero-blog添加新模板,但我对新模板的 GraphQL 查询被拒绝:
warning The GraphQL query in the non-page component
"/Users/mc/workspaces/mc/src/templates/NoteBookTemplate.js" will not be run.
Queries are only executed for Page or Layout components. Instead of a query,
co-locate a GraphQL fragment and compose that fragment into the query (or other
fragment) of the top-level page or layout that renders this component.
For more
info on fragments and composition see:
http://graphql.org/learn/queries/#fragments
Run Code Online (Sandbox Code Playgroud)
文件夹结构如下:
--src
--components
--images
--pages
--templates
--CategoryTemplate.js
--NotebookTemplate.js
--PageTemplate.js
--PostTemplate.js
--theme
--utils
Run Code Online (Sandbox Code Playgroud)
NotebookTemplate.js 是我添加的新模板(用于使用 Nteract 的 Gatsby 插件渲染 Jupyter 笔记本)。
我添加的模板查询的语法与其他模板相同(我在 GraphiQL 中可见的内容中有一个示例笔记本)。
export const query = graphql`
query NotebookQuery($slug: String!) {
jupyterNotebook(fields: { slug: { eq: $slug } }) {
html
internal {
content
}
}
}
`
Run Code Online (Sandbox Code Playgroud)
我什至尝试使用镜像其他模板之一的简单查询创建准系统模板(甚至尝试使用已更改组件名称的模板的精确副本),但仍然收到相同的警告(随后没有渲染笔记本。例如,PageTemplate.js 具有以下查询(对 gatsby 构建没有任何抱怨)。
export const pageQuery = graphql`
query PageByPath($slug: String!) {
page: markdownRemark(fields: { slug: { eq: $slug } }) {
id
html
frontmatter {
title
}
}
site {
siteMetadata {
facebook {
appId
}
}
}
}
`;
Run Code Online (Sandbox Code Playgroud)
为什么不在页面或布局文件夹中的文件中的这些查询也不会引发此错误?是否有其他文件允许解决方法?FWIW,这是我试图实现的实际模板。
import React from 'react'
import PropTypes from "prop-types";
import 'katex/dist/katex.min.css'
import { ThemeContext } from "../layouts";
const NotebookTemplate = ({ data }) => {
const post = data.jupyterNotebook
const notebookJSON = JSON.parse(post.internal.content)
return (
<React.Fragment>
<p>
This notebook is displayed in the <strong>client-side</strong> using
react component
<code>NotebookPreview</code>
from
<a href="https://github.com/nteract/nteract/tree/master/packages/notebook-preview">
<code>@nteract/notebook-preview</code>.
</a>
</p>
<NotebookPreview notebook={notebookJSON} />
</React.Fragment>
);
};
NotebookTemplate.propTypes = {
data: PropTypes.object.isRequired
};
export default NotebookTemplate;
export const query = graphql`
query NotebookQuery($slug: String!) {
jupyterNotebook(fields: { slug: { eq: $slug } }) {
html
internal {
content
}
}
}
`;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3575 次 |
| 最近记录: |