到目前为止,我发现的每个教程都通过Apollo,Relay或其他一些魔术框架在GraphQL中实现了分页.我希望在这里找到类似问题的答案,但它们不存在.我理解如何设置查询,但我不知道如何实现解析器.
有人能指出我正确的方向吗?我正在使用mongoose/MongoDB和ES5,如果这有帮助的话.
编辑:值得注意的是,如果您选择使用,学习GraphQL的官方网站没有分页条目graphql.js.
编辑2:我喜欢有些人在做研究之前投票结束问题,而其他人则利用他们的知识帮助他人.无论你怎么努力,你都无法阻止进步.(:
我对 AppSync 错误处理有疑问。我想发送errorInfo对象以及错误响应,我尝试了$util.error. 根据文件:
https://docs.aws.amazon.com/appsync/latest/devguide/resolver-util-reference.html
\n\n\n\n\n\n\n
$util.error(String, String, Object, Object)抛出自定义错误。如果模板检测到请求或调用结果有错误,则可以在请求或响应映射模板中使用该模板。此外,还可以指定 errorType 字段、data 字段和 errorInfo 字段。数据值将添加到 GraphQL 响应中错误内的相应错误块中。注意:数据将根据查询选择集进行过滤。errorInfo 值将添加到 GraphQL 响应中错误内相应的 error\n 块中。注意:errorInfo 将不会根据查询选择集进行过滤。
\n
这是我的 ResponseMappingTemplate 的样子:
\n\n#if( $context.result && $context.result.errorMessage )\n $utils.error($context.result.errorMessage, $context.result.errorType, $context.result.data), $context.result.errorInfo)\n#else\n $utils.toJson($context.result.data)\n#end\nRun Code Online (Sandbox Code Playgroud)\n\n这是我在解析器上所做的:
\n\nvar result = {\n data: null,\n errorMessage: \'I made this error\',\n errorType: \'ALWAYS_ERROR\',\n errorInfo: {\n errorCode: 500,\n validations: [\n {\n fieldName: \'_\',\n result: false,\n reasons: [\n \'Failed! Yay!\'\n ]\n }\n …Run Code Online (Sandbox Code Playgroud) 尝试gatsby-node通过外包一些代码来重构我的文件。现在正在尝试在我的中执行此操作gatsby-node:
const createBlogPostPages = require("./gatsby-utils/createBlogPostPages");
exports.createPages = async ({ actions, graphql, reporter }) => {
//...some code
await createBlogPostPages({ actions, graphql, reporter });
//...some code
}
Run Code Online (Sandbox Code Playgroud)
mycreateBlogPostPages位于不同的文件中,如下所示:
const path = require("path");
module.exports = async function({ actions, graphql, reporter }) {
const { createPage } = actions;
const blogArticles = await graphql(`
{
allMdx(filter: { fileAbsolutePath: { regex: "/content/blog/.*/" } }) {
edges {
node {
id
fileAbsolutePath
fields {
slug
}
frontmatter {
title …Run Code Online (Sandbox Code Playgroud) 我们正在使用 NestJS-typescript 开发微服务。
它们每个都公开一个 GraphQL 模式。为了公开单个图,我们也在 NestJS 中使用联合服务。
我试图与“@graphql-eslint/eslint-plugin”集成。
该插件的作用分为2个:
第 2# 节角色需要有关模式文件的附加信息。正如我之前所说,有许多架构和操作文件位于 monorepo 中。
正如文档中提到的,为了允许这些角色,应该定义“parserOptions.schema”。无论我做了什么,我都无法设置该字段,并且收到以下错误:
错误:规则“unique-argument-names”需要设置“parserOptions.schema”并加载架构。有关更多信息,请参阅https://github.com/dotansimha/graphql-eslint#extended-linting-rules-with-graphql-schema
在我的 POV 中,我只希望 linter 访问.graphql整个项目中的所有文件,但我不知道为什么这不起作用以及为什么需要这个字段,因为我已经将 linter 定义为仅 lint*.graphql文件。
我正在运行下面的 GraphQL 查询来在 dynamodb 表上创建数据,但得到的响应是“未授权访问 Client 类型上的 createClient”
为什么会发生这种情况。
GraphQL 查询:
`mutation addClient{
createClient(input:{
fullName: "Jhon Smith"
title: "Software Engineer"
organization: "AWS"
contactNo: "+341289655524"
email: "smithj@amazon.com"
country: "Canada"
address: "AN/458, Norton place, Down Town"
}){
fullName
}
}`
Run Code Online (Sandbox Code Playgroud)
回复 :
{
"data": {
"createClient": null
},
"errors": [
{
"path": [
"createClient"
],
"data": null,
"errorType": "Unauthorized",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "Not Authorized to access createClient on type Client"
} …Run Code Online (Sandbox Code Playgroud) 我们如何在 graphQL 中的公共列上进行数据连接。
例如在 SQL 中:选择 t.name 和 z.address,其中 t.id=z.id;
这是如何由 graphQL 查询管理的。
我正在以编程方式构建 GraphQL 架构,并且需要Timestamp标量类型;Unix 纪元时间戳标量类型:
const TimelineType = new GraphQLObjectType({
name: 'TimelineType',
fields: () => ({
date: { type: new GraphQLNonNull(GraphQLTimestamp) },
price: { type: new GraphQLNonNull(GraphQLFloat) },
sold: { type: new GraphQLNonNull(GraphQLInt) }
})
});
Run Code Online (Sandbox Code Playgroud)
不幸的是,GraphQL.js没有aGraphQLTimestamp也没有 aGraphQLDate类型,所以上面的方法不起作用。
我期待一个Date输入,我想将其转换为时间戳。我将如何创建自己的 GraphQL 时间戳类型?
如果是,应覆盖以下哪一种方法以及如何覆盖?我无法找到有关如何覆盖每个示例的示例。
visitSchema(schema: GraphQLSchema)visitScalar(scalar: GraphQLScalarType)visitObject(object: GraphQLObjectType)visitFieldDefinition(field: GraphQLField<any, any>)visitArgumentDefinition(argument: GraphQLArgument)visitInterface(iface: GraphQLInterfaceType)visitUnion(union: GraphQLUnionType)visitEnum(type: GraphQLEnumType)visitEnumValue(value: GraphQLEnumValue)visitInputObject(object: GraphQLInputObjectType)visitInputFieldDefinition(field: GraphQLInputField)我的直觉会说,visitObject(object: GraphQLObjectType)因为type Query是一个GraphQLObjectType.
我有一个 GraphQL 驱动的应用程序。查询和变异部分运行良好。我尝试添加 GraphQL 订阅。
服务器 GraphQL 订阅部分代码的灵感来自apollographql/subscriptions-transport-ws的自述文件中的演示。
另请检查代码中的注释以获取更多详细信息。
import Koa from 'koa';
import Router from 'koa-router';
import graphqlHTTP from 'koa-graphql';
import asyncify from 'callback-to-async-iterator';
import { SubscriptionServer } from 'subscriptions-transport-ws';
import firebase from 'firebase-admin';
import { execute, subscribe } from 'graphql';
import { GraphQLObjectType, GraphQLString } from 'graphql';
const MeType = new GraphQLObjectType({
name: 'Me',
fields: () => ({
name: { type: GraphQLString },
// ...
}),
});
const listenMe = async (callback) => {
// Below …Run Code Online (Sandbox Code Playgroud) 我想使用该库https://github.com/apollographql/graphql-tag 我正在寻找比我更聪明的人,了解如何实际使用它。
假设我有一个 GraphQL 查询文档,如下所示:
const query = gql`
{
user(id: 5) {
...User_user
}
}
${userFragment}
`
Run Code Online (Sandbox Code Playgroud)
现在如何获取要添加到 http 正文请求中的字符串?我最终得到一个对象,它允许我进行一些内省和操作,这很好,但是如何获取服务器请求的实际正文字符串?
我想我错过了一些明显的东西......
graphql-js ×10
graphql ×9
javascript ×4
aws-appsync ×2
node.js ×2
apollo ×1
ecmascript-5 ×1
eslint ×1
gatsby ×1
graphql-tag ×1
join ×1
koa ×1
mongodb ×1
mongoose ×1
scalar ×1
schema ×1
typescript ×1
vtl ×1