最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Finding one element in graphQL by idemail - Stack Overflow

programmeradmin2浏览0评论

I'm trying to make a findOneByEmail/id for graphQL. I saw a couple of questions, blog posts, and videos, but they didn't help my case. I know I have to add a filter, but I have to be missing something

Here are my resolvers

const users = [
  {id: 1, email:'[email protected]',password:'zaq1@WSX', pons:[{value:'test'}]},
  {id: 2, email:'[email protected]',password:'ZAQ!2wsx', pons:[{value:'tset'}]}
];
const pons = [{value: 'test'}];
module.exports = {
  Query: {
    users: () => users,
    pons: () => pons,
  }
};

typeDefs

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

module.exports = gql`  
  type Pon {
      value: String!
  }
  type User {
    id: Int
    email: String!
    password: String!
    pons: [Pon]!
  }
  type Query {
      findUser(id: Int): [User]
      users: [User]
      pons: [Pon]
  }
`;

app.js

const express = require('express');
const { ApolloServer } = require('apollo-server-express');
const typeDefs = require('./graphql/typeDefs.js');
const resolvers = require('./graphql/resolvers.js');

const server = new ApolloServer({typeDefs, resolvers});

const app = express();
server.applyMiddleware({ app });

app.listen({ port: 4000 }, () =>
  console.log(`
发布评论

评论列表(0)

  1. 暂无评论