我有一个 Angular/Apollo GraphQL 实现,它基于 GraphQl 端点生成打字稿代码,该端点呈现模式。我可以通过 Postman 使用查询访问端点并返回结果。但是,当我通过 npm 运行“graphql-codegen --config codegen.yml”时,出现此错误:
“错误:必须提供查询根类型”
服务器端是使用 GraphQL ASPNetCore 的 .Net Core 实现。我定义了 4 个不同的查询,每个查询都通过 graphiql 工作。
关于为什么查询根类型现在被返回为空的任何想法?
我正在用 做一个简单的测试@apollo/react-hooks,我收到了这个错误:
ApolloError.ts:46 Uncaught (in promise) Error: Network error: Unexpected end of JSON input
at new ApolloError (ApolloError.ts:46)
at Object.error (QueryManager.ts:255)
at notifySubscription (Observable.js:140)
at onNotify (Observable.js:179)
at SubscriptionObserver.error (Observable.js:240)
at observables.ts:15
at Set.forEach (<anonymous>)
at Object.error (observables.ts:15)
at notifySubscription (Observable.js:140)
at onNotify (Observable.js:179)
at SubscriptionObserver.error (Observable.js:240)
at Object.error (index.ts:81)
at notifySubscription (Observable.js:140)
at onNotify (Observable.js:179)
at SubscriptionObserver.error (Observable.js:240)
at httpLink.ts:184
Run Code Online (Sandbox Code Playgroud)
当我尝试使用这样的突变时:
ApolloError.ts:46 Uncaught (in promise) Error: Network error: Unexpected end of JSON input
at new ApolloError (ApolloError.ts:46) …Run Code Online (Sandbox Code Playgroud) 我是阿波罗的新手,我有两个阿波罗服务,我想通过使用阿波罗联合来联合:
产品服务:
extend type Query {
job(id: String!): Job
}
type Seo {
title: String!
description: String!
keywords: String!
}
type Product @key(fields: "id") {
id: ID!
title: String!
seo: Seo!
}
Run Code Online (Sandbox Code Playgroud)
员工服务:
extend type Query {
staffMember(id: String!): StaffMember
}
type Seo {
title: String!
description: String!
keywords: String!
}
type StaffMember @key(fields: "id") {
id: ID!
title: String!
seo: Seo!
}
Run Code Online (Sandbox Code Playgroud)
如何在两个对象的响应对象中使用类型Seo?创建接口 Seo 并实现 StaffMemberSeo 和 ProductSeo 的过程是否正确,或者是否有允许我在两个服务中定义完全相同类型的注释?
我正在使用 NextJS、Apollo 和 React(钩子)开发一个网络应用程序。
我有一个表格,它在注册过程的第一步中询问访问者的姓名。提交表单时,名称将保存在 Apollo 缓存中,访问者将被重定向到下一页。
import React, { useState } from 'react';
import Router , {useRouter} from 'next/router';
import { useApolloClient } from '@apollo/react-hooks';
const NameForm = props => {
const [name, setName] = useState("");
const client = useApolloClient();
const router = useRouter();
const handleSubmit = e => {
e.preventDefault();
if(!name) return;
client.writeData({ data: { name } });
router.push('/user/register');
}
return (
<form onSubmit={handleSubmit}>
<div>
<label htmlFor="name">Naam</label>
<div>
<input type="text" id="name" name="name" value={name} onChange={e => setName(e.target.value)} />
<button …Run Code Online (Sandbox Code Playgroud) 你好,所以我在我的 ReactJS 应用程序上使用 apollo-client 已经有一段时间了。我刚刚注意到,有时当我使用useQuery钩子时,执行完全忽略skip参数,并继续onCompleted(尽管没有任何数据)。有趣的是,它也没有向我的端点发出 API 请求。但是,如果我只是设置skip为 false,那么一切正常(如预期)。
此外,每次我使用useQuerywith时都不会发生这种情况skip,它似乎适用于某些而不是其他。
为什么 apollo 忽略skip参数并onCompleted立即使用空数据执行?有没有修复(除了useLazyQuery)?
const userQuery = useQuery(GET_USER, {
variables: {
value: userId,
},
skip: true,
onCompleted: props => {
console.log(`props => `, props)
const {
user: { type, role, firstName, lastName, permissions },
} = props;
setValue('firstName', firstName);
setValue('lastName', lastName);
setValue(
'type',
userTypes.find(({ value }) => value === type),
);
setValue( …Run Code Online (Sandbox Code Playgroud) apollo reactjs react-apollo apollo-client react-apollo-hooks
存储错误:应用程序试图写入一个没有提供 id 的对象,但存储已经包含了该对象的 UsersPermissionsUser:1 的 id。试图写入的 selectionSet 是:
{
"kind": "Field",
"name": { "kind": "Name", "value": "user" },
"arguments": [],
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
"selections": [
{ "kind": "Field", "name": { "kind": "Name", "value": "username" }, "arguments": [], "directives": [] },
{ "kind": "Field", "name": { "kind": "Name", "value": "__typename" } }
]
}
}
Run Code Online (Sandbox Code Playgroud)
1-在 YouTube 上运行的Watch Book Mobile 应用程序:https : //youtu.be/sBM-ErjXWuw
2-在 YouTube 上观看问题视频了解详情:https : …
我正在学习 apollo 和 graphQL,并且有一个简单的应用程序,它显示一个数据列表,带有一个添加到数组的 fetchMore 函数。
我想删除 updateQuery,因为它已被弃用并使用新的字段策略合并功能。当前缓存设置和 updateQuery 如下所示:
const cache = new InMemoryCache({
typePolicies: {
client_client: {
fields: {
// add local only value to clients
isEdited: {
read(value = false) {
// when writing the new value return new value or false as default
return value;
},
}
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
const onFetchMore = () => {
fetchMore({
variables: {
offset: page
},
updateQuery: (previousResult, { fetchMoreResult, queryVariables }) => {
return {
...previousResult,
client_client: [ …Run Code Online (Sandbox Code Playgroud) 我试图在一个返回 Apollo Client 的类中构建一个简单的函数。这是我的代码:
import appConfig from 'config/app-config';
import { ApolloClient, InMemoryCache, createHttpLink } from '@apollo/client';
import LocalStorageKeys from 'constants/local-storage-keys';
import { setContext } from '@apollo/client/link/context';
export class ApolloClientServiceImpl {
private cache: InMemoryCache;
constructor() {
this.cache = new InMemoryCache();
}
createApolloClient(idToken: string): unknown {
const httpLink = createHttpLink({
uri: appConfig.hasura.url,
});
const authLink = setContext((_, { headers }) => {
let bearerToken = localStorage.getItem(LocalStorageKeys.TOKEN);
if (idToken) {
bearerToken = idToken;
}
return {
headers: {
...headers,
authorization: bearerToken ? `Bearer …Run Code Online (Sandbox Code Playgroud) 希望有人可以帮助我解决这个小问题,我现在无法弄清楚。
问题陈述:
为了在我的DataLoader. 这DataLoader是在单独的路径中定义的/loaders。在我的resolvers.js文件中,我可以使用dataSources.userAPI.getAllUsers(). 但是如何在我的服务器端应用程序中的任何其他地方访问它,比如我/loaders文件夹中的fe ?我只是不知道如何访问我的上下文对象,然后将令牌传递给DataLoader,然后从我的 API 加载数据,然后将此数据传递给我的resolvers.js文件。非常感谢每一个帮助,我不知道如何解决这个简单的事情..谢谢!
代码来了:
索引.js
const express = require('express');
const connectDB = require('./config/db');
const path = require('path');
var app = express();
const cors = require('cors')
const axios = require('axios')
// apollo graphql
const { ApolloServer } = require('apollo-server-express');
const DataLoader = require('dataloader')
const { userDataLoader } = require('./loaders/index')
// Connect Database
connectDB();
// gql import
const typeDefs = require('./schema'); …Run Code Online (Sandbox Code Playgroud) 我已经在互联网上搜索了有关此问题的解决方案,但还没有遇到过。我正在创建一个新帖子并将其添加到 Apollo 根查询缓存中。出于某种原因,即使newData使用新查询返回一个新对象,它也不会分配给缓存。
const [createPost, { error }] = useMutation(CREATE_POST_MUTATION, {
variables: values,
update(proxy, result) {
const data = proxy.readQuery({
query: FETCH_POSTS_QUERY,
});
let newData = [...data.getPosts];
newData = [result.data.createPost, ...newData];
proxy.writeQuery({ query: FETCH_POSTS_QUERY, data: newData });
values.body = '';
},
});
Run Code Online (Sandbox Code Playgroud) apollo ×10
graphql ×5
react-apollo ×3
reactjs ×3
javascript ×2
dataloader ×1
next.js ×1
react-hooks ×1
strapi ×1
typescript ×1
vue-apollo ×1
vue.js ×1