我想发送没有子节的graphql变异请求
mutation _ {
updateCurrentUser(fullName: "Syava", email: "fake@gmail.com")
}
Run Code Online (Sandbox Code Playgroud)
我正在接受
{
"errors": [
{
"message": "Field \"updateCurrentUser\" of type \"User\" must have a sub selection.",
...
}
]
}
Run Code Online (Sandbox Code Playgroud)
添加{id}请求工作正常,但我不想要
也是架构代码
const userType = new GraphQLObjectType({
name: 'User',
fields: () => ({
id: { type: new GraphQLNonNull(GraphQLString) },
fullName: { type: GraphQLString },
email: { type: GraphQLString },
}),
});
type: userType,
args: {
fullName: { type: GraphQLString },
email: { type: new GraphQLNonNull(emailType) },
password: { type: GraphQLString }, …Run Code Online (Sandbox Code Playgroud) 这是我在这里的第一篇讨论帖子。我通过奥德赛学到了Apollo+ 。目前,我正在使用Next.js构建自己的项目,该项目需要从 2 个GraphQL 端点获取数据。GraphQL
我的问题:如何使用GraphQL 从多个端点ApolloClient获取数据?
以下是我的第一个端点的代码:
import { ApolloClient, InMemoryCache, createHttpLink } from "@apollo/client";
const client = new ApolloClient({
ssrMode: true,
link: createHttpLink({
uri: "https://api.hashnode.com/",
credentials: "same-origin",
headers: {
Authorization: process.env.HASHNODE_AUTH,
},
}),
cache: new InMemoryCache(),
});
export default client;
Run Code Online (Sandbox Code Playgroud) 有人尝试开发GraphQL而不是RESTful API吗?有人可以给予现实生活(不仅是理论上的)利弊.基本上从我的研究中我发现GraphQL的功能正是为了得到你所需要的东西.使用REST API时,您经常需要发出一系列请求,并且可以轻松获取比实际需要更多的信息.
是否值得花时间研究和学习GraphQL?任何引起你注意的bug或showstoppers?
GraphQL中是否有可能具有也是联合的输入类型?
就像是:
const DynamicInputValueType = new GraphQLUnionType({
name: 'DynamicInputType',
types: [GraphQLString, GraphQLFloat, GraphQLInt]
})
Run Code Online (Sandbox Code Playgroud)
但也可以用作突变的输入?
嗨,我正在努力学习GraphQL语言.我有以下代码片段.
// Welcome to Launchpad!
// Log in to edit and save pads, run queries in GraphiQL on the right.
// Click "Download" above to get a zip with a standalone Node.js server.
// See docs and examples at https://github.com/apollographql/awesome-launchpad
// graphql-tools combines a schema string with resolvers.
import { makeExecutableSchema } from 'graphql-tools';
// Construct a schema, using GraphQL schema language
const typeDefs = `
type User {
name: String!
age: Int!
}
type Query {
me: …Run Code Online (Sandbox Code Playgroud) 我在 Apollo、GraphQL 和 Nuxtjs 项目中工作,在设置 Apollo 配置时我收到了这个警告:
link.js:38 Error: You are calling concat on a terminating link, which will have no effect
at new LinkError (linkUtils.js:41)
at concat (link.js:38)
at ApolloLink.webpackJsonp../node_modules/apollo-link/lib/link.js.ApolloLink.concat (link.js:65)
at link.js:13
at Array.reduce (<anonymous>)
at from (link.js:13)
at createApolloClient (index.js:58)
at webpackJsonp../.nuxt/apollo-module.js.__webpack_exports__.a (apollo-module.js:66)
at _callee2$ (index.js:140)
at tryCatch (runtime.js:62)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
link.js:38 Error: You are calling concat on a terminating link, which will have no effect
at new LinkError (linkUtils.js:41)
at concat (link.js:38)
at ApolloLink.webpackJsonp../node_modules/apollo-link/lib/link.js.ApolloLink.concat (link.js:65)
at link.js:13 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Apollo Server 的Upload标量将文件直接发送到 S3。我的架构:
const { gql } = require('apollo-server-express')
module.exports = gql`
extend type Mutation {
createPicture(
name: String!
picture: Upload!
): Picture!
}
type Picture {
name: String!
picture: String!
}
`
Run Code Online (Sandbox Code Playgroud)
解析器:
const { combineResolvers } = require('graphql-resolvers')
const isAuthenticated = require('./auth')
const { uploadPhoto } = require('../services/picture')
module.exports = {
Mutation: {
createPicture: combineResolvers(
isAuthenticated,
async (
parent,
{ name, picture = null },
{ models, me }
) => {
const { …Run Code Online (Sandbox Code Playgroud) graphql中的AST是什么?我正在使用graphql-js.它对任何事情有何帮助?
任何文档中的任何内容似乎都不能解释AST是什么
我正在使用Gatsbyjs和NetlifyCMS构建一个网站.我已经开始使用这个启动器https://github.com/AustinGreen/gatsby-starter-netlify-cms,我现在正在尝试自定义它.
我想在markdown文件的frontmatter中使用自定义变量,如下所示:
---
templateKey: mirror
nazev: ?ernobílá
title: Black and White
cena: '2700'
price: '108'
thumbnail: /img/img_1659.jpeg
---
Run Code Online (Sandbox Code Playgroud)
我想用GraphQL访问这些数据.我使用gatsby-source-filesystem和gatsby-transform-remark.这是我的查询:
{
allMarkdownRemark {
edges {
node {
frontmatter {
templateKey
nazev
title
cena
price
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我无法让GraphQL读取我自己的变量,它只识别title和templateKey(那些已经在启动器中使用过的).我收到此错误:
{
"errors": [
{
"message": "Cannot query field \"nazev\" on type \"frontmatter_2\".",
"locations": [
{
"line": 7,
"column": 11
}
]
},
{
"message": "Cannot query field \"cena\" on type \"frontmatter_2\".",
"locations": [
{
"line": …Run Code Online (Sandbox Code Playgroud) 我们已经实现了模式拼接,其中GraphQL服务器从两个远程服务器获取模式并将它们拼接在一起.当我们只使用Query和Mutations时,一切都运行正常,但现在我们有一个用例,我们甚至需要缝合订阅,远程模式已经通过它实现了auth.
我们很难搞清楚如何通过网关将connectionParams中收到的授权令牌从客户端传递到远程服务器.
这就是我们如何反省架构:
API网关代码:
const getLink = async(): Promise<ApolloLink> => {
const http = new HttpLink({uri: process.env.GRAPHQL_ENDPOINT, fetch:fetch})
const link = setContext((request, previousContext) => {
if (previousContext
&& previousContext.graphqlContext
&& previousContext.graphqlContext.request
&& previousContext.graphqlContext.request.headers
&& previousContext.graphqlContext.request.headers.authorization) {
const authorization = previousContext.graphqlContext.request.headers.authorization;
return {
headers: {
authorization
}
}
}
else {
return {};
}
}).concat(http);
const wsLink: any = new WebSocketLink(new SubscriptionClient(process.env.REMOTE_GRAPHQL_WS_ENDPOINT, {
reconnect: true,
// There is no way to update connectionParams dynamically without resetting connection
// connectionParams: () => …Run Code Online (Sandbox Code Playgroud) apollo graphql apollo-server graphql-subscriptions graphql-tools
graphql ×10
graphql-js ×4
apollo ×3
javascript ×2
gatsby ×1
markdown ×1
next.js ×1
node.js ×1
remarkjs ×1
rest ×1