我已经在graphQL中编写了一个架构和解析器,但是当我尝试在GraphQL游乐场中运行此错误时,出现了以下错误:
$k
有人对为什么会这样吗? @DEL_LineID是从数据库调用的参数。
我在下面添加了我的代码:
模式:
"errors": [
{
"message": "{\"message\":\"Procedure or function 'usp_ROAdditionalItemSentStockCheckOnly' expects parameter '@DEL_LineID', which was not supplied.\",\"locations\":[{\"line\":2,\"column\":3}],\"path\":[\"packingErrorStockCheck\"],\"extensions\":{\"code\":\"INTERNAL_SERVER_ERROR\",\"exception\":{\"name\":\"RequestError\",\"message\":\"Procedure or function 'usp_ROAdditionalItemSentStockCheckOnly' expects parameter '@DEL_LineID', which was not supplied.\",\"code\":\"EREQUEST\",\"number\":201,\"lineNumber\":0,\"state\":4,\"class\":16,\"serverName\":\"DEVSQL03\\\\SQL2017\",\"procName\":\"dbo.usp_ROAdditionalItemSentStockCheckOnly\",\"precedingErrors\":[],\"stacktrace\":[\"RequestError: Procedure or function 'usp_ROAdditionalItemSentStockCheckOnly' expects parameter '@DEL_LineID', which was not supplied.\",\" at /mnt/c/stuart.roper/development/stock-api/node_modules/mssql/lib/tedious.js:1065:17\",\" at Connection.emit (events.js:180:13)\",\" at Parser.<anonymous> (/mnt/c/stuart.roper/development/stock-api/node_modules/tedious/lib/connection.js:204:16)\",\" at Parser.emit (events.js:180:13)\",\" at Parser.<anonymous> (/mnt/c/stuart.roper/development/stock-api/node_modules/tedious/lib/token/token-stream-parser.js:42:15)\",\" at Parser.emit (events.js:180:13)\",\" at addChunk (/mnt/c/stuart.roper/development/stock-api/node_modules/readable-stream/lib/_stream_readable.js:291:12)\",\" at readableAddChunk (/mnt/c/stuart.roper/development/stock-api/node_modules/readable-stream/lib/_stream_readable.js:278:11)\",\" at Parser.Readable.push (/mnt/c/stuart.roper/development/stock-api/node_modules/readable-stream/lib/_stream_readable.js:245:10)\",\" at Parser.Transform.push (/mnt/c/stuart.roper/development/stock-api/node_modules/readable-stream/lib/_stream_transform.js:148:32)\"]}}}"
}
索引:
import { gql } from 'apollo-server-express';
const PackingErrorStockCheck = gql`
type PackingErrorStockCheck {
success: Boolean!
}
input PackingErrorStockCheckInput {
delLineId: ID!
userId: Int!
}
type PackingErrorStockCheckPayload {
success: Boolean!
}
`;
export default PackingErrorStockCheck;
解析器:
const RootQuery = gql`
type RootQuery {
mainStockStatusMatrix(input: StockMatrixInput!): StockMatrixTable
accessoryStockStatusMatrix(input: StockMatrixInput!): StockMatrixTable
stockStatusDetail(input: StockStatusDetailInput!): StockStatusDetail
stockBySite(input: StockBySiteInput!): StockBySite
}
type RootMutation {
stockAdjustment(input: StockAdjustmentInput!): StockAdjustmentPayload!
packingErrorStockCheck(input: PackingErrorStockCheckInput!): PackingErrorStockCheckPayload!
}
`;
const SchemaDefinition = gql`
schema {
query: RootQuery
mutation: RootMutation
}
`;
export const typeDefs = [
SchemaDefinition,
RootQuery,
gql(DateFormatting),
StockMatrixTable,
StockStatusDetail,
gql(jsonSchema),
StockBySite,
StockAdjustment,
PackingErrorStockCheck
];
export default makeExecutableSchema({
typeDefs,
resolvers,
allowUndefinedInResolve: false,
schemaDirectives
});
解析器索引:
import { addStoredProcedureParameters } from '@labs/api-core';
export const checkStock = async (inputs, app) => {
const {
_dbHelper: { newRequest, sql }
} = app;
const request = await newRequest();
const requestParameters = [
{
b2InputParameter: 'DEL_LineID',
type: sql.UniqueIdentifier,
incomingInputParameter: 'delLineId'
},
{
b2InputParameter: 'SYS_UserID',
type: sql.SmallInt,
incomingInputParameter: 'userId'
}
];
try {
addStoredProcedureParameters(request, inputs, requestParameters);
const result = await request.execute('dbo.usp_ROAdditionalItemSentStockCheckOnly');
console.log('result', result);
if (result.returnValue === 0) {
return {
success: true
};
}
return {
success: false
};
} catch (err) {
throw err;
}
};
export default {
RootMutation: {
packingErrorStockCheck: (_, input, { app }) => checkStock(input, app)
}
};