我正在将 HotChocolate (11.2.2) 与 EF Core 一起使用,并且想要过滤子属性。根据 GraphQL 文档,这应该可以通过在导航属性上使用过滤器关键字来实现,但 HotChocolate 失败了。
我的架构:
type A {
Name: string,
RefTo: [B]
}
type B {
TypeName: string,
Value: int
}
Run Code Online (Sandbox Code Playgroud)
这是由 EF 支持的,我IQueryable<A>向 HotChocolate 提供了一个。
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
public IQueryable<A> GetAs([Service] Context db) => db.As.AsSingleQuery().AsNoTrackingWithIdentityResolution();
Run Code Online (Sandbox Code Playgroud)
现在我只想包含那些等于的Bs ,如下所示:TypeName"ExampleType"
query {
As {
Name,
RefTo(where: { TypeName: { eq: "ExampleType" } })
{
TypeName,
Value
}
}
}
Run Code Online (Sandbox Code Playgroud)
但 HotChcolate 似乎并不明白这一点,并说道:
Unknown argument "where" on field "A.RefTo".validation …
我正在尝试完成有关Android/GraphQL 的 AWS 教程,但惨败。我的构建在通过以下命令自动生成的代码段上失败
amplify codegen models
Run Code Online (Sandbox Code Playgroud)
用作源的架构是...
type NoteData
@model
@auth (rules: [ { allow: owner } ]) {
id: ID!
name: String!
description: String
image: String
}
Run Code Online (Sandbox Code Playgroud)
...生成的代码的失败部分是...
/** This is an auto generated class representing the NoteData type in your schema. */
@SuppressWarnings("all")
@ModelConfig(pluralName = "NoteData", authRules = {
@AuthRule(allow = AuthStrategy.OWNER, ownerField = "owner", identityClaim = "cognito:username", **provider** = "userPools", operations = { ModelOperation.CREATE, ModelOperation.UPDATE, ModelOperation.DELETE, ModelOperation.READ })
})
public final class NoteData implements …Run Code Online (Sandbox Code Playgroud) 我正在使用 Apollo-client 将突变发布到我的 graphql 服务器。突变完成后,我想重新获取该数据。我尝试使用挂钩refetchQueries中的参数useMutation,但是当我执行代码时收到此错误:
查询选项是必需的。您必须在查询选项中指定您的 GraphQL 文档。
这是发送突变的代码行:
const [addUser, { data, loading, error }] =
useMutation(ADD_USER_QUERY, {
refetchQueries:[GET_USERS_QUERY]
});
Run Code Online (Sandbox Code Playgroud)
这是我的查询(硬编码参数是为了查看问题是否是由于传递变量引起的):
export const ADD_USER_QUERY = gql`
mutation {
createUser(name: "Albert Einstein", email: "albert@yahoo.ca") {
id
name
}
}
`;
Run Code Online (Sandbox Code Playgroud)
谢谢你!
我是新手,尝试执行 GraphQL 查询,data根据用户单击的链接在页面上进行更新(检查onClick下面代码中的两个 s)。
当用户单击链接时,handleSubmit还应该通过更新 URL router.push(更新后的 URL 应类似于:)http://localhost:3000/bonustype?=value,而不刷新任何页面。但是,当我尝试使用时,router.push出现以下错误:
服务器错误错误:未找到路由器实例。您应该只在应用程序的客户端内使用“next/router”。
单击链接并更新 URL 后,GraphQL 查询应使用更新的 slug(具有链接中的值)再次“执行”。
被这个问题困扰了几个小时,感谢任何帮助或意见。该代码来自我的主索引页面,运行时的当前网址是localhost:3000/。
你会如何解决这个问题?
import { useState } from "react";
import { useRouter } from "next/router";
import Layout from "../components/Layout";
import Head from "next/head";
import Featured from "../components/index/Featured";
import { API_URL } from "@/config/index";
import {
ApolloClient,
inMemoryCache,
gql,
InMemoryCache,
} from "@apollo/client";
export default function HomePage({ casinos }) {
const router = useRouter(); …Run Code Online (Sandbox Code Playgroud) 我有一个带有 apollo-server 的 graphql api。我使用 Graphql Playground 测试了所有查询、突变和订阅。
我正在使用 Ferry 包作为 grapqhl 客户端在 Flutter 中开发客户端应用程序。所有查询和突变都可以正常工作,但订阅却不能。
发送订阅请求时,会建立 Websocket 连接,但不会启动订阅。我在 Graphql Playground 上测试了订阅,连接请求消息如下所示
但对于渡轮客户端,它会卡在connection_init上
var link = WebSocketLink(
"ws://localhost:4000/graphql",
initialPayload: {"subscriptionParam": arg},
);
var client = Client(link: link);
client.request(request).listen((data) {//request is an object from autogenerated class from ferry
log(data.toString());//never gets here
}, onError: (error, stack) {
log("Subscription error: " + error.toString());
});
Run Code Online (Sandbox Code Playgroud)
我的代码有什么问题?请帮助!
我使用 MongoDb、Cloudinary(用于图像)和 Heroku(用于部署)制作了一个 Strapi 应用程序。我在部署 Graphql 之前安装了它。它在本地主机的开发模式下工作正常,graphql 游乐场显示正常。但在生产中,我在尝试显示 graphql 游乐场时遇到错误。它只显示一个空白页面,其中包含以下消息:
缺少 GET 查询
如果 url“some_name.heroku.com/graphql”不起作用,如何使用 graphql/Apollo 查询我的数据?
我正在尝试在 ASP.NET Core 中使用 Hot Chocolate 设置 GraphApi。
现在我想将我的应用程序拆分为多个项目/组件。有一个 Users 组件,其中的 UsersMutation 包含 1 个字段:
public sealed class UsersMutation
{
public Task CreateUser([Service] ICreateUserMutationHandler handler, CreateUserParameters parameters)
=> handler.Handle(parameters);
}
Run Code Online (Sandbox Code Playgroud)
我尝试将其添加到 GraphQl 架构中,如下所示:
public sealed class Mutation
{
public UsersMutation Users => new UsersMutation();
}
Run Code Online (Sandbox Code Playgroud)
配置:
public static class GraphApiConfiguration
{
public static IServiceCollection AddGraphApi<TQuery, TMutation>(this IServiceCollection services)
where TQuery : class
where TMutation : class
{
services.AddGraphQLServer()
.AddQueryType<TQuery>()
.AddMutationType<TMutation>();
services.AddScoped<TQuery>();
services.AddScoped<TMutation>();
return services;
}
}
Run Code Online (Sandbox Code Playgroud)
最后在startup.cs中:
services.AddGraphApi<Query, Mutation>();
Run Code Online (Sandbox Code Playgroud)
但我在尝试查看游乐场中的架构时遇到以下错误: …
根据阿波罗文档:
如果您的服务器使用 cookie 进行身份验证,您可以将端点配置为与https://studio.apollographql.com共享这些 cookie 。要进行此设置,您的 cookie 值必须包含
SameSite=None; Secure. 此外,这些 CORS 标头必须存在于服务器对 Studio 的响应中:Run Code Online (Sandbox Code Playgroud)Access-Control-Allow-Origin: https://studio.apollographql.com Access-Control-Allow-Credentials: true
我已经完成了那里提到的所有事情。我使用的是express,所以我使用cors中间件来设置标头:
app.use(
cors({
credentials: true,
origin: "https://studio.apollographql.com",
})
);
Run Code Online (Sandbox Code Playgroud)
但每当我在操场上打开“允许 Cookie”的开关时,状态都会变成红色(即“无法到达服务器”)。我的编辑器和nodemon没有显示错误。关闭“允许 Cookie”开关可以解决问题,但会禁用 Cookie 功能。
我该如何解决这个问题?
我希望使用 Hot Chocolate 的过滤来查询一种数据类型;然后将过滤后的输出转换为另一种类型,然后将其作为 IQueryable 返回。但我似乎无法找到捕获过滤器输入以开始转换的方法。
这是我想要实现的目标的示例:
给定数据类
public class TypeA
{
public string Foo { get; set; }
}
public class TypeB
{
public string Fizz { get; set; }
public string Buzz { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我希望能够创建一个查询端点,例如
public class Query
{
[UseDbContext(typeof(DbContext))]
[UseFiltering(typeof(TypeA))]
public IQueryable<TypeB> GetTypeB(
[ScopedService] DbContext context,
[SomeAttributeToCaptureTheFilter] Filter filter) // <- this is the line I'm trying to figure out
{
IQueryable<TypeA> filteredTypeAs = context.TypeA.Filter(filter); // .Filter() doesn't exist, its just for example.
IQueryable<TypeB> …Run Code Online (Sandbox Code Playgroud) 在解析器中,throw new createError.BadRequest("bad input")错误被劫持Graphql-shield并显示为
{
"errors": [
{
"message": "Not Authorised!",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"myMutation"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"Error: Not Authorised!",
Run Code Online (Sandbox Code Playgroud)
这是 Apollo 服务器设置
const schema = buildSubgraphSchema([
{ typeDefs: await typeDefs(), resolvers },
]);
const apolloServer = new ApolloServer({
schema: applyMiddleware(schema, permissions),
context: async ({ req, res }) => new AuthenticatedContext(req, res)
});
Run Code Online (Sandbox Code Playgroud)
如何返回实际发生的错误?
graphql ×10
apollo ×2
c# ×2
hotchocolate ×2
reactjs ×2
.net-core ×1
aws-amplify ×1
cookies ×1
deployment ×1
flutter ×1
heroku ×1
next.js ×1
strapi ×1
subscription ×1
url ×1