标签: graphql

Graphql - 从生成的 JSON 文件创建模式

我正在尝试创建一个自定义 graphql 架构以在我的 graphql Yoga 服务器上使用。graphql Yoga 服务器只是另一个 graphql API 的代理,我已经设法从中检索格式的模式JSON。以下是该架构的预览:

{
  "data": {
    "__schema": {
      "queryType": {
        "name": "Query"
      },
      "mutationType": null,
      "subscriptionType": null,
      "types": [
        {
          "kind": "OBJECT",
          "name": "Core",
          "description": null,
          "fields": [
            {
              "name": "_meta",
              "description": null,
              "args": [],
              "type": {
                "kind": "NON_NULL",
                "name": null,
                "ofType": {
                  "kind": "OBJECT",
                  "name": "Meta",
                  "ofType": null
                }
              },
              "isDeprecated": false,
              "deprecationReason": null
            },
            {
              "name": "_linkType",
              "description": null,
              "args": [],
              "type": {
                "kind": "SCALAR",
                "name": "String",
                "ofType": …
Run Code Online (Sandbox Code Playgroud)

javascript node.js graphql

0
推荐指数
1
解决办法
2618
查看次数

Nestjs 中多个 graphql 解析器实现的问题

我刚刚开始学习 NestJS 和 GraphQL。UserResolver我从 中定义的单个解析器类开始UserModule。此类提供读取用户列表或特定用户的方法。方法用 装饰@Query()user.graphql提供文件,GraphQL 在 中初始化AppModule,所有这些都如文档中所述。一切正常,我可以通过 Insomnia Tool 或 Playground 获取用户或特定用户的列表。我很开心!

现在我创建了第二个模块,RoleModule. 我创建了一个role.graphql文件和一个类,我基本上RoleResolver复制了为. 类型的 GraphQL 类型定义以及文件中的查询定义均被识别。不被识别的是我在类中的实现,它们没有被调用。UserRoleRolerole.graphqlQuery()RoleResolver

如果我将所有这些Role相关的@Query()定义放入UserResolver类中,这些Role相关的查询现在就会被调用。

这是预期的行为吗?我是否需要将所有 GraphQL 查询定义放入一个类中?是否可以将 NestJS-GraphQL 解析器实现分散到多个模块上?难道我做错了什么?请帮忙。

node.js typescript graphql nestjs

0
推荐指数
1
解决办法
2105
查看次数

我应该使用express-graphql还是appolo-server-graphql

我正在开发一个使用 graphql ajd 的 Express 后端,我不知道是否需要使用 express-graphql 或 appolo-server-graphql 库。感谢您的帮助!

graphql express-graphql

0
推荐指数
1
解决办法
1504
查看次数

如何使用 Babel 在 JavaScript 类中编写正确的私有方法?

我正在从 Apollo 服务器做 GraphQL 教程。现在我尝试从这部分添加批处理 - https://www.apollographql.com/docs/apollo-server/features/data-sources/#batching

我知道我可以在 TypeScript 中使用private。但不知道如何在JS中使用。

据我搜索,我安装了两个 babel 插件,class-properties并且private-methods.

// .babelrc

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "current"
        }
      }
    ]
  ],
  "plugins": [
    ["@babel/plugin-proposal-class-properties", { "loose": true }],
    ["@babel/plugin-proposal-private-methods", { "loose": true }],
    "@babel/plugin-proposal-object-rest-spread",
    "@babel/plugin-proposal-async-generator-functions"
  ]
}
Run Code Online (Sandbox Code Playgroud)

这是代码:

// .babelrc

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "current"
        }
      }
    ]
  ],
  "plugins": [
    ["@babel/plugin-proposal-class-properties", { "loose": true }],
    ["@babel/plugin-proposal-private-methods", { "loose": true }], …
Run Code Online (Sandbox Code Playgroud)

javascript node.js babeljs graphql

0
推荐指数
1
解决办法
1883
查看次数

POST 请求是否缓存在 Django 中?

我想根据发送给它的 POST 数据来缓存一些视图。

装饰器会django.views.decorators.cache.cache_page自动执行此操作还是我需要以某种方式调整它?对于后一种情况,我该怎么办?

我正在尝试缓存 GraphQL POST 请求。

django django-cache graphql

0
推荐指数
1
解决办法
833
查看次数

如何使用 IoC 访问 HotChocolate (GraphQL) 请求的查询

我正在尝试使用 hotchocolate 提高 sql 查询性能。为此,我想在应用程序的另一层访问 hotchololate 生成的查询请求。我能找到的唯一方法是拦截请求,将我需要的信息存储在 HttpContext 项中,然后在我需要的地方注入 IHttpContextAccessor。

services.AddQueryRequestInterceptor(GraphQLRequestInterceptor);
...
private Task GraphQLRequestInterceptor(HttpContext context, IQueryRequestBuilder requestBuilder, CancellationToken cancellationToken)
{
    IReadOnlyQueryRequest request = requestBuilder.Create();
    context.Items.Add("graph", request);
}
Run Code Online (Sandbox Code Playgroud)

然后通过注入 IHttpContextAccessor 来恢复它

public ClientesQueries(Microsoft.AspNetCore.Http.IHttpContextAccessor contextAccessor)
{
   var queryRequest = contextAccessor.HttpContext.Items["graph"] as IReadOnlyQueryRequest;
}
Run Code Online (Sandbox Code Playgroud)

使用该代码,我可以创建一个表达式来查询数据库,仅查找客户端请求的数据。

有更好的方法来实现这一目标吗?

entity-framework-core graphql hotchocolate

0
推荐指数
1
解决办法
3696
查看次数

使用 Cognito 用户池 ID 在 AWS 上调用 graphql api

我花了两天时间谷歌搜索解决方案。但未能找到合适的解决方案。我收到以下信息。

Cognito Identity pool ids: 
INT: "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
CRT: "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
PSS: "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
PREPROD: "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
PROD: "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

Api url : https://xxxxxxxxxxxxxxxx.appsync-api.us-east-2.amazonaws.com/graphql
Api id : 63xxxxxxxxxxxxxxxxxx
Appsync name : TheAppSyncName
Authorization mechanism : IAM auth
Run Code Online (Sandbox Code Playgroud)

我发现在 Android 中有几种不同的方法可以做到这一点,https://github.com/awslabs/aws-mobile-appsync-sdk-android

但找不到 .net c# AWS sdk 的示例。

有人可以解释一下上述值的含义以及如何使用它来调用 .net C# 中的 graphql API 吗?

更新:经过多次尝试,我最终没有任何解决方案。然后我发现 appsync 不能与 c# .net 中的给定信息一起使用。除了上述内容之外,我还获得了 AWS 帐号和未经身份验证的角色 ARN。

c# amazon-cognito .net-core graphql aws-appsync

0
推荐指数
1
解决办法
1946
查看次数

无法查询类型查询的字段注册

开始摆弄 GraphQL,但我遇到了这个错误。不确定这是架构定义还是查询中的问题。

const express_graphql = require('express-graphql')
const { buildSchema } = require('graphql')
const users = require('../users/translator')

const schema = buildSchema(`
    type User {
        id: ID
        email: String
        role: String
    }
    type Query {
        user(id: ID!): User
        users: [User]
        token(email: String!, password: String!): String!
    }
    type Mutation {
        signup(email: String!, password: String!, role: String!): ID
    }`
)

const resolvers = {
    users: users.getAll,
    user: users.getById,
    token: users.login,
    signup: users.create,
}

module.exports = app => {
    // GraphQL route
    app.use('/graphql', express_graphql({
        schema, …
Run Code Online (Sandbox Code Playgroud)

node.js express graphql express-graphql

0
推荐指数
1
解决办法
7991
查看次数

无法从 Kotlin 中生成的 Apollo 类构建查询(缺少 .builder())

我无法构建由 Android Apollo 库生成的查询。

我有以下 .gpaphql 文件:

mutation LogIn($username: String!, $password: String!) {
  tokenAuth(username: $username, password: $password) {
    token
  }
}
Run Code Online (Sandbox Code Playgroud)

它为此生成了一个 Kotlin 请求文件:

// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL plugin from the GraphQL queries it found.
// It should not be modified by hand.
//
import com.apollographql.apollo.api.InputFieldMarshaller
import com.apollographql.apollo.api.Mutation
import com.apollographql.apollo.api.Operation
import com.apollographql.apollo.api.OperationName
import com.apollographql.apollo.api.Response
import com.apollographql.apollo.api.ResponseField
import com.apollographql.apollo.api.ResponseFieldMapper
import com.apollographql.apollo.api.ResponseFieldMarshaller
import com.apollographql.apollo.api.ResponseReader
import com.apollographql.apollo.api.internal.SimpleOperationResponseParser
import com.apollographql.apollo.internal.QueryDocumentMinifier
import com.apollographql.apollo.response.ScalarTypeAdapters …
Run Code Online (Sandbox Code Playgroud)

android kotlin apollo graphql apollo-android

0
推荐指数
1
解决办法
2285
查看次数

尝试在react中获取图像的src路径

我在使用 React 和 graphQL 获取图形 CMS 的图像 src 路径时遇到问题。问题是路径总是返回 null。我确信这个问题已经被问过很多次了,但为了让我学习,我只需要看看我做错了什么。

我在 graphQL 中的查询是这样的:

query {
products {
  id
  name
  price
  description
  createdAt
  image {
    id
    url
  }
}
Run Code Online (Sandbox Code Playgroud)

}

我总是得到所有其他信息,但不是图像 src (返回 null)。

我的代码如下:

import React from 'react';

const Product = (props) => {
  return (
      <div className="col-sm-4">
          <div className="card" style={{width: "18rem"}}>
            <img src={props.product.image.url} className="card-img-top" alt={props.product.name}/>
            <div className="card-body">
              <h5 className="card-title">{props.product.name}</h5>
              <p className="card-title">$ {props.product.price}</p>
              <p className="card-title">{props.product.description}</p>
              <button className="btn btn-primary" onClick={() => props.addItem(props.product)}>Buy now</button>
            </div>
          </div>
      </div>
  );
}
export default Product; …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs graphql

0
推荐指数
1
解决办法
562
查看次数