这是我的简单 graphql express 应用程序
const express = require('express');
const graphqlHTTP = require('express-graphql');
const app = express();
app.use(
'/graphql',
graphqlHTTP({
graphiql: true,
})
);
app.listen(4000, () => {
console.log("listening for request!");
});
Run Code Online (Sandbox Code Playgroud)
我在运行时遇到以下错误:
graphqlHTTP({
^
TypeError: graphqlHTTP is not a function
at Object.<anonymous> (D:\PersonalProjects\GraphQL\server\app.js:7:5)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
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,在学习教程的过程中,我遇到了一些我无法理解的行为.假设我们已经在模式中定义了类型:
type Link {
id: ID!
url: String!
description: String!
postedBy: User
votes: [Vote!]!
}
Run Code Online (Sandbox Code Playgroud)
由于docs votes: [Vote!]!意味着该字段应该是不可为空的,并且数组本身也应该是不可为空的.但是,在教程的作者显示查询示例之后,对于某些链接,它返回votes字段的空数组.像这样:
{
"url": "youtube.com",
"votes": []
},
{
"url": "agar.io",
"votes": []
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:不是"非可空"在graphQL模式中意味着"空",或者它只是graphQL服务器的某种错误行为(我的意思是它返回任何数组而没有警告应该有一些由于模式) .
谢谢!
我尝试在 GraphQL 的 Apollo 客户端中更改 addTypeName: false
apollo.create({
link: httpLinkWithErrorHandling,
cache: new InMemoryCache({ addTypename: false }),
defaultOptions: {
watchQuery: {
fetchPolicy: 'network-only',
errorPolicy: 'all'
}
}
Run Code Online (Sandbox Code Playgroud)
但它可以工作,并且会在控制台中抛出以下消息
fragmentMatcher.js:26 You're using fragments in your queries, but either don't have the addTypename:true option set in Apollo Client, or you are trying to write a fragment to the store without the __typename.Please turn on the addTypename option and include __typename when writing fragments so that Apollo Clientcan accurately match fragments.
Run Code Online (Sandbox Code Playgroud)
,
Could not …Run Code Online (Sandbox Code Playgroud) 我在我的middlware服务器上使用远程架构拼接.我能够在中间件服务器上远程获取架构,在中间件服务器上定义我的路由.
app.use('/graphql', graphqlHTTP((request,res) => {
const startTime = Date.now();
return {
schema: remoteSchema
graphiql: false,
extensions({ document, variables, operationName, result }) {
return {
// here I am not getting extensions which I have on my another server as below.
console.log(res); // this does not have additional info and response headers
console.log(result); // this only has response against the query
}
};
}));
Run Code Online (Sandbox Code Playgroud)
我在结果中得到查询的结果,但没有得到响应标题和附加信息,这是我在其他解析器所在的其他服务器上添加的扩展的一部分.
{
"data": {
"records": {
"record": [{
"id": 1,
},
{
"id": 2,
}
],
}, …Run Code Online (Sandbox Code Playgroud) 有人可以帮我这个,我的设置如下,在Apollo 2.0之前,我有一个server.js,其中我使用了express和graphql-server-express我有一个只有http的cookie会话,当用户登录时我设置了jwt令牌作为cookie,它在浏览器中设置为仅限http.在后续请求中,我验证浏览器传回的cookie.一切正常,我可以从任何其他解析器中的req.session.token访问令牌,并验证保存在cookie会话中的jwt令牌.
server.js
import express from 'express';
import { graphqlExpress, graphiqlExpress } from 'graphql-server-express';
import { ApolloEngine } from 'apollo-engine';
import bodyParser from 'body-parser';
import cors from 'cors';
import cookieSession from 'cookie-session';
import schema from './schema/';
?
const server = express();
?
server.use(
cookieSession({
name: 'session',
keys: 'k1,k2',
maxAge: 30 * 60 * 1000,
domain: '.mydomain.com',
path: '/',
}),
);
?
const corsOptions = {
origin: 'http://local.mydomain.com:3000',
credentials: true,
methods: ['GET', 'PUT', 'POST', 'OPTIONS'],
};
?
server.use(cors(corsOptions));
?
server.use(
'/graphql', …Run Code Online (Sandbox Code Playgroud) 已经安装了 graphql-upload,执行
import { graphqlUploadExpress } from 'graphql-upload';
并收到此错误:错误:在 graphql-upload/package.json 中没有定义“exports”main
依赖项:
"graphql-upload": "^14.0.0",
"graphql": "15.8.0",
"graphql-request": "^4.2.0",
"graphql-tools": "^8.2.0",
"@nestjs/axios": "^0.0.7",
"@nestjs/common": "^8.4.1",
"@nestjs/config": "^1.1.5",
"@nestjs/core": "^8.4.1",
"@nestjs/graphql": "^9.1.2",
"@nestjs/platform-express": "^8.0.0",
Run Code Online (Sandbox Code Playgroud)
节点版本:v16.10.0
我开始使用带有反应继电器的graphQl.我遵循了一些教程,我可以在突变和查询的帮助下获取和发布.一切正常,但我的问题是,
例如:如果我从数据库中获取数据,我可以进入特定的DB/TABLE.同样,我想知道graphql存储数据的位置.
我搜索了许多网站,他们正在告诉如何使用qraphql,但我无法找到我的问题的答案.我需要澄清这方面的问题.有人可以帮我解决这个问题.
我正在尝试从 python 更改我的 Shopify 商店。我是 graphQL 的新手,我已经能够使用 graphiQL 进行更改,但我不确定如何直接从我的代码中进行更改。
这是我的 make 查询文件,它已成功用于简单查询
`import requests
def make_query(self, query, url, headers):
"""
Return query response
"""
request = requests.post(url, json={'query': query}, headers=headers)
if request.status_code == 200:
return request.json()
else:
raise Exception("Query failed to run by returning code of {}. {}".format(request.status_code, query))`
Run Code Online (Sandbox Code Playgroud)
现在在 graphiQL 中起作用的突变的一个例子是这样的:
"mutation {customerCreate(input: {email: 'wamblamkazam@send22u.info', password: 'password'}) {userErrors { field message}customer{id}}}"
但是当我将它传递给我的 make_query 函数时,它给出了这个错误
{'errors': [{'message': 'Parse error on "\'" (error) at [1, 41]', 'locations': [{'line': 1, 'column': 41}]}]} …Run Code Online (Sandbox Code Playgroud) 我正在尝试安装express-graphql,但出现此错误。请帮忙!
npm install --save express-graphql
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: rest-api@1.0.0
npm ERR! Found: graphql@16.2.0
npm ERR! node_modules/graphql
npm ERR! graphql@"^16.2.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer graphql@"^14.7.0 || ^15.3.0" from express-graphql@0.12.0
npm ERR! node_modules/express-graphql
npm ERR! express-graphql@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this …Run Code Online (Sandbox Code Playgroud) express-graphql ×10
graphql ×10
node.js ×5
javascript ×3
apollo ×2
express ×2
graphql-js ×2
nestjs ×1
npm ×1
parse-error ×1
python ×1
relay ×1
relaymodern ×1