信息参数是阿波罗GraphQL解析器类型签名空(info argument is empty in

2019-09-26 13:52发布

我工作的这个库https://github.com/ilyaskarim/wertik-js叫Wertik JS做GraphQL + REST API更容易,在解析器,当我控制台日志info ,它表明不确定的。 对于每个模块,我创建动态解析器​​,以使事情更容易为开发商谁将会使用这个库。

let object = {
    create: async (_:any, args:any, context:any,info: any) => {
      console.log(info); // This will be undefined
      let v = await validate(validations.create,args.input);
      let {success} = v;
      if (!success) {
        throw new ApolloError("Validation error",statusCodes.BAD_REQUEST.number,{list: v.errors})
      }
      try {
        let createModel = await model.create(args.input);
        pubsub.publish(`${camelCase(moduleName)}Created`, { [`${camelCase(moduleName)}Created`]: createModel });
        return createModel;
      } catch (e) {
        return internalServerError(e);
      }
    },
}

行: https://github.com/ilyaskarim/wertik-js/blob/ec813f49a14ddd6a04680b261ae4ef2aadc2b1a5/src/framework/dynamic/resolvers.ts#L102

在阿波罗服务器文档中描述的信息https://www.apollographql.com/docs/apollo-server/essentials/data/#resolver-type-signature ,它说:这个自变量包含有关查询的执行状态信息,包括字段名,从根的路径,场,等等。 对我来说,不幸的是,它越来越不确定。

要重现该问题:

  1. 下载https://github.com/ilyaskarim/wertik-js/tree/development
  2. 纱线安装
  3. 转到例子/演示
  4. 运行node index.js
  5. 现在去的http://本地主机:1209 /
  6. 输入此突变,例如:

    突变{CREATEROLE(输入:{名: “性Asd”}){名称}}

  7. 该行执行这一突变https://github.com/ilyaskarim/wertik-js/blob/ec813f49a14ddd6a04680b261ae4ef2aadc2b1a5/src/framework/dynamic/resolvers.ts#L102
  8. 并返回未定义的控制台上。

这就是我设置的应用程序:

const { ApolloServer } = require('apollo-server');

import mutations from "./loadAllMutations";
import queries from "./loadAllQueries";
import resolvers from "./loadAllResolvers";
import subscriptions from "./loadAllSubscriptions";
import schemas from "./loadAllSchemas";
import generalSchema from "./../helpers/generalSchema";

export default function (rootDirectory: string,app: any,configuration: object) {
  let allMutations = mutations(rootDirectory);
  let allQueries=  queries(rootDirectory);
  let allSchemas = schemas(rootDirectory);
  let allResolvers = resolvers(rootDirectory);
  let allSubscriptions = subscriptions(rootDirectory);
  let {validateAccessToken} = require(`${rootDirectory}/framework/predefinedModules/user/auth`).default;
  let mainSchema  = `
    ${generalSchema}
    ${allSchemas}
    type Subscription {
      ${allSubscriptions}
    }
    type Mutation {
      ${allMutations}
    }
    type Query {
      ${allQueries}
    }
    schema {
      query: Query
      mutation: Mutation
      subscription: Subscription
    }
  `;
  const server = new ApolloServer({ 
    typeDefs: mainSchema, 
    resolvers: allResolvers,
    context: async (a: any) => {
      await validateAccessToken(a.req);
    }
  });
  server.listen(1209).then(({ url, subscriptionsUrl }) => {
    console.log(`Server ready at ${url}`);
    console.log(`Subscriptions ready at ${subscriptionsUrl}`);
  });
}

可能是什么可能的原因?

Answer 1:

你截断由内而外的解析器接收到的参数此模块 。 如果你需要一个功能分配给某个对象的财产,这是好多了,只是不喜欢这样写道:

mutations: {
  [`create${moduleName}`]: mutations[`create${moduleName}`],
},

这不仅更简洁,但同时也意味着你没有无意中留下过一个参数,它是在这里发生了什么。



文章来源: info argument is empty in Apollo GraphQL resolver type signature