我想在我的GraphQL模式中使用@cypher指令查询一个节点上的字段。
但是,当我查询该字段时,得到的结果是Resolve function for \"Link.x\" returned undefined。
我使用来自链接的x上的指令的模式如下
scalar URI
interface IDisplayable{
"Minimal data necessary for the object to appear on screen"
id: ID!
label: String
story: URI
}
interface ILink{
"""
A link must know to what nodes it is connected to
"""
x: Node! @cypher(statement: "MATCH (this)-[:X_NODE]->(n:Node) RETURN n")
y: Node!
"""
if optional=true then sequence MAY be used to define a set of options
"""
optional: Boolean
}
interface INode{
synchronous: Boolean
unreliable: Boolean
}
type Node implements INode & IDisplayable{
id: ID!
label: String!
story: URI
synchronous: Boolean
unreliable: Boolean
}
type Link implements ILink & IDisplayable{
id: ID!
label: String!
x: Node! @cypher(statement: "MATCH (this)-[:X_NODE]->(n:Node) RETURN n")
y: Node!
story: URI
optional: Boolean
}当查询a链接及其x属性时,我得不到定义。使用我为y编写的自定义解析器,不管它如何工作。当然,我可以留下手写的解析器,但它的许多代码是不必要的。
这是index.js:
require( 'dotenv' ).config();
const express = require( 'express' );
const { ApolloServer } = require( 'apollo-server-express' );
const neo4j = require( 'neo4j-driver' );
const cors = require( 'cors' );
const { makeAugmentedSchema } = require( 'neo4j-graphql-js' );
const typeDefs = require( './graphql-schema' );
const resolvers = require( './resolvers' );
const app = express();
app.use( cors() );
const URI = `bolt://${ process.env.DB_HOST }:${ process.env.DB_PORT }`;
const driver = neo4j.driver(
URI,
neo4j.auth.basic( process.env.DB_USER, process.env.DB_PW ),
);
const schema = makeAugmentedSchema( { typeDefs, resolvers } );
const server = new ApolloServer( {
context: { driver },
schema,
formatError: ( err ) => {
return {
message: err.message,
code: err.extensions.code,
success: false,
stack: err.path,
};
},
} );
const port = process.env.PORT;
const path = process.env.ENDPOINT;
server.applyMiddleware( { app, path } );
app.listen( { port, path }, () => {
console.log( `Server listening at http://localhost:${ port }${ path }` );
} );其中"graphql-schema.js“是
const fs = require( 'fs' );
const path = require( 'path' );
const schema = './schemas/schema.graphql';
const encoding = 'utf-8';
let typeDefs = '';
typeDefs += fs.readFileSync( path.join( __dirname, schema ) )
.toString( encoding );
module.exports = typeDefs;谢谢你的建议
发布于 2020-04-16 16:51:16
我发现,如果我为查询编写自定义解析器,Apollo提供的指令不起作用。然而,我意识到我可以让Apollo创建我需要的查询,所以我删除了我的自定义实现,这对我来说很有效。
因此,在我的解析器中,我必须删除查询的实现,这些实现将获取用@cypher查询注释的字段,然后我可以将该指令放入我的模式中,它们工作得很好。
https://stackoverflow.com/questions/61236482
复制相似问题