请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

apollo/server用它mock数据,前端页面不停的发送请求?

各种库的安装及配置都没有问题,但是运行mock的server后,前端不停的在发请求,不知道是何原因?以下是文件内容:
mock/index.js:
import { ApolloServer } from ‘@apollo/server’;
import { startStandaloneServer } from ‘@apollo/server/standalone’;
import { addMocksToSchema } from ‘@graphql-tools/mock’;
import { makeExecutableSchema } from ‘@graphql-tools/schema’;
import { faker } from ‘@faker-js/faker/locale/zh_CN’

const typeDefs = `#graphql
type Mutation {
create(params: UserInput!): UserType!
deleteUser(id: String!): Boolean!
updateUser(id: String!, user: UserInput!): UserType!
}

type Query {
""“这个查询用户信息的”""
find(id: String!): UserType!
}

input UserInput {
account: String!
name: String!
password: String!
tel: String!
}

type UserType {
account: String!
id: String!
name: String!
tel: String!
}
`;

const resolvers = {
UserType: {
name: () => faker.name.firstName() + faker.name.lastName()
}
};

const mocks = {
Int: () => 6,
Float: () => 22.1,
String: () => ‘Hello’,
};

const server = new ApolloServer({
schema: addMocksToSchema({
schema: makeExecutableSchema({ typeDefs, resolvers }),
mocks,
preserveResolvers: true,
}),
});

startStandaloneServer(server, { listen: { port: 4000 } });

console.log(🚀 Server listening);

图片描述
图片描述

图片描述
图片描述

正在回答 回答被采纳积分+3

1回答

黑石 2023-05-06 16:59:43

是装了什么插件吗? 我看报错是 clientstream.launchdarkly.com 这个网站。

0 回复 有任何疑惑可以回复我~
  • 提问者 huazhouzhang #1
    没刻意装什么插件,以下 是我的package.json文件:
    {
      "name": "onlineedu",
      "private": true,
      "version": "0.0.0",
      "type": "module",
      "scripts": {
        "dev": "vite",
        "build": "tsc && vite build",
        "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
        "preview": "vite preview",
        "mock": "node mock/index.js"
      },
      "dependencies": {
        "@apollo/client": "^3.7.14",
        "antd-mobile": "^5.30.0",
        "graphql": "^16.6.0",
        "react": "^18.2.0",
        "react-dom": "^18.2.0"
      },
      "devDependencies": {
        "@apollo/server": "^4.7.1",
        "@faker-js/faker": "^7.6.0",
        "@graphql-tools/mock": "^8.7.20",
        "@graphql-tools/schema": "^9.0.19",
        "@types/react": "^18.0.28",
        "@types/react-dom": "^18.0.11",
        "@typescript-eslint/eslint-plugin": "^5.57.1",
        "@typescript-eslint/parser": "^5.57.1",
        "@vitejs/plugin-react": "^4.0.0",
        "eslint": "^8.38.0",
        "eslint-plugin-react-hooks": "^4.6.0",
        "eslint-plugin-react-refresh": "^0.3.4",
        "typescript": "^5.0.2",
        "vite": "^4.3.2"
      }
    }
    回复 有任何疑惑可以回复我~ 2023-05-08 09:46:56
  • 黑石 回复 提问者 huazhouzhang #2
    我的意思是说,你查查为什么 clientstream.launchdarkly.com 这个地址在报错。推荐加入课程 qq 群,这样可以更好为你答疑。
    回复 有任何疑惑可以回复我~ 2023-05-08 15:27:13
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信