标签: graphql-js

Apollo客户端graphql查询与reactJS中的动态字段

这是我用于获取用户详细信息的示例 graphql 查询(我在 ReactJS 中使用 Apollo 客户端)

如果我只需要idname作为响应,我使用此查询

{
 getUserDetails {
   id
   name
 }
}
Run Code Online (Sandbox Code Playgroud)

或者如果我只需要iduserType我使用此查询:

{
 getUserDetails {
   id
   userType
 }
}
Run Code Online (Sandbox Code Playgroud)

有什么方法可以动态传递字段名称和用户类型(基本上动态传递字段)而不是再次编写整个查询?

reactjs graphql graphql-js react-apollo apollo-client

2
推荐指数
1
解决办法
4635
查看次数

如何在 Graphql 模式中定义日期数据类型?

我收到来自外部 API 的 LASTUPDATE: 1579443364 响应,
如何在架构中定义数据类型以便将其转换为日期格式?

像这样的格式: Mon Jan 19 2020 00:44:04

GraphQL 模式语言支持:

Int
Float
字符串
Id
布尔值

在此输入图像描述

javascript node.js graphql graphql-js

2
推荐指数
1
解决办法
3万
查看次数

为什么子字段在不同界面时会发生冲突?

我正在尝试使用 GraphQL(Apollo 服务器)查询单个 MongoDB 文档 ( trivia),但其中一个文档字段遇到问题。

LightningRoundQuestion.answer并且PictureRoundPicture.answer应该返回一个String,并且MultipleChoiceRoundQuestion.answer应该返回一个Int。查看架构:

schema

const typeDefs = gql`
  # ROOT TYPES ==================================================
  type Query {
    trivia(_id: String!): Trivia
  }

  # INTERFACES ==================================================
  interface Round {
    type: String!
    theme: String!
    pointValue: Int!
  }

  type LightningRound implements Round {
    type: String!
    theme: String!
    pointValue: Int!
    questions: [LightningRoundQuestion]
  }

  type MultipleChoiceRound implements Round {
    type: String!
    theme: String!
    pointValue: Int!
    questions: [MultipleChoiceRoundQuestion]
  }

  type PictureRound implements Round { …
Run Code Online (Sandbox Code Playgroud)

node.js apollo graphql graphql-js apollo-server

2
推荐指数
1
解决办法
2374
查看次数

Graphql 上传获取“‘操作’多部分字段中的 JSON 无效”

我一直在努力弄清楚如何让文件上传在 graphql 中工作。

\n

这是我的基本实现。

\n
\n// eslint-disable-next-line import/no-extraneous-dependencies\nconst { ApolloServer, gql }             = require(\'apollo-server-express\')\n// eslint-disable-next-line import/no-extraneous-dependencies\nconst express                      = require(\'express\')\n\n\nconst typeDefs = gql`  \n  type File {\n    filename: String!\n    mimetype: String!\n    encoding: String!\n  }\n  \n  type Query {\n    _ : Boolean\n  }\n  \n  type Mutation {\n    singleUpload(file: Upload!): File!,\n    singleUploadStream(file: Upload!): File!\n  }\n`;\n\nconst resolvers = {\n  Mutation: {\n    singleUpload: (parent, args) => {\n      return args.file.then(file => {\n        const {createReadStream, filename, mimetype} = file\n\n        const fileStream = createReadStream()\n\n        return file;\n      });\n …
Run Code Online (Sandbox Code Playgroud)

javascript graphql-js apollo-server

2
推荐指数
1
解决办法
3903
查看次数

gql 和 buildSchema 有什么区别?

graphql-js buildSchemaapollo-server 有什么区别gql?他们似乎做着非常相似的工作。

graphql graphql-js apollo-server graphql-tag

2
推荐指数
1
解决办法
753
查看次数

如何将javascript变量传递给graphql查询?

我有一个超级简单的 GraphQl 查询,但我无法根据输入使查询动态化。假设您将在 javascript 中获得一个字符串,并将其传递给查询,它是如何完成的?以下面的示例为例,我如何替换产品中 Sku 字段上的硬编码字符串“3111”,而是插入变量 myString 中的值?当我尝试传递它时,我只是收到错误。

let myString = "3111"

`query getProductBySku {
        site {
          product(sku: "3111") {
            id
            entityId
            name
            sku
          }
        }
      }`
Run Code Online (Sandbox Code Playgroud)

javascript reactjs graphql graphql-js

2
推荐指数
1
解决办法
3369
查看次数

突变中的单个JSON参数

下面我试图example用一个object-arg 设置一个突变credentials。我以前曾进行过此工作,然后突然停止在JSON部分上工作失败。为什么我无法通过发送json credentials

import {
  GraphQLSchema,
  GraphQLObjectType,
  GraphQLString,
  GraphQLInt,
  GraphQLInputObjectType,
  GraphQLNonNull,
  graphql
} from 'graphql'


let requestType = new GraphQLInputObjectType({
  name: 'Request',
  fields: {
    name: {type: GraphQLString},
  }
})

let responseType = new GraphQLObjectType({
  name: 'Response',
  fields: {
    name: {type: GraphQLString},
    age: {type: GraphQLInt}
  }
})

let schema = new GraphQLSchema({
  query:  new GraphQLObjectType({
    name: 'Query',
    fields: {
      author: {
        type: GraphQLString,
        resolve: (source, args, context, info) => {
          return 'Thomas Reggi'
        }
      }
    } …
Run Code Online (Sandbox Code Playgroud)

json graphql graphql-js

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

我们可以使用cy.request调用graphql吗?赛普拉斯

我在Google上搜索过类似内容,cypress request with graphql但我看到很多人都在谈论mock up serverstub等等。但是我无法找到完整的示例以及如何cypress.iographqlusing请求一起使用。

有谁知道它是如何cy.request工作的,graphql或者在哪里可以找到它的解决方案?

在此先感谢您的帮助。

javascript unit-testing graphql graphql-js cypress

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

具有必需参数的GraphQL mutator

我正在为GraphQL模式编写一个变体:

const Schema = new GraphQLSchema({
  mutation: new GraphQLObjectType({
    name: 'Mutation',
    fields: () => ({
      person: {
        type: GraphQLString,
        args: {
          name: {type: GraphQLString},
          school: {type: GraphQLString},
        },
        resolve: mutatePerson,
      },
    }),
  }),
});
Run Code Online (Sandbox Code Playgroud)

我想确保mutatePerson只有同时存在nameschool参数时,该方法才能起作用。我该如何检查?

graphql graphql-js

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

如何在一个请求中使用不同的参数多次运行一个突变?

我有一个突变:

const createSomethingMutation = gql`
  mutation($data: SomethingCreateInput!) {
    createSomething(data: $data) {
      something {
        id
        name
      }
    }
  }
`;
Run Code Online (Sandbox Code Playgroud)

如何Something在一个请求中创建多个?我需要像这样在我的GraphQL服务器上创建一个新的Mutation吗:

mutation {
  addManySomethings(data: [SomethingCreateInput]): [Something]
} 
Run Code Online (Sandbox Code Playgroud)

还是有一种方法可以createSomethingMutation在一个请求中多次使用来自Apollo Client的现有方法和不同的参数?

apollo graphql graphql-js react-apollo apollo-client

1
推荐指数
2
解决办法
1645
查看次数