我正在编写一个Web应用程序,使用Go作为后端.我正在使用这个GraphQL库(链接)和Echo Web框架(链接).问题是graphql-go
库使用context
Go中的包,同时Echo
使用自己的自定义上下文,并删除了对标准context
包的支持.
我的问题是,有没有办法使用context.Context作为echo.Context,在下面的例子中?
api.go
func (api *API) Bind(group *echo.Group) {
group.Use(middleware.JWTWithConfig(middleware.JWTConfig{
SigningKey: []byte("SOME_REAL_SECRET_KEY"),
SigningMethod: "HS256",
}))
group.GET("/graphql", api.GraphQLHandler)
group.POST("/query", echo.WrapHandler(&relay.Handler{Schema: schema}))
}
Run Code Online (Sandbox Code Playgroud)
graphql.go
func (r *Resolver) Viewer(ctx context.Context, arg *struct{ Token *string }) (*viewerResolver, error) {
token := ctx.Value("user").(*jwt.Token) // oops on this line, graphql-go uses context.Context, but the echo middleware provides echo.Context
...
}
Run Code Online (Sandbox Code Playgroud)
我如何使我的graphql解析器可以使用echo上下文.非常感谢,任何帮助表示赞赏.
执行命令时出现以下错误:npm start
Cannot find module 'loadash'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (<Path...>/data/dbConnector.js:3:1)
at Module._compile (module.js:643:30)
at loader (<Path...>\node_modules\babel-register\lib\node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (<Path...>\node_modules\babel-register\lib\node.js:154:7)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (<Path...>/data/resolvers.js:2:1)
at Module._compile (module.js:643:30)
at loader (<Path...>\node_modules\babel-register\lib\node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (<Path...>\node_modules\babel-register\lib\node.js:154:7)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
[nodemon] app …
Run Code Online (Sandbox Code Playgroud) Run Code Online (Sandbox Code Playgroud)npm ERR! code ENOSELF npm ERR! Refusing to install package with name "graphql" under a package npm ERR! also called "graphql". Did you name your project the same npm ERR! as the dependency you're installing? npm ERR! npm ERR! For more information, see:
我正在尝试在 typedef 中使用 Number 类型和 Array 类型作为 GraphQL 中的 Product 类型。但 GraphQL 在控制台中给了我一些错误。这是我第一次使用 GraphQL。
Unknown type "Array".
Unknown type "Number".
Run Code Online (Sandbox Code Playgroud)
这是我试图创建的 typedef。
type Product {
sku: String
productName: String
isNewProduct: Boolean
isPromo: Boolean
promoType: String
promoPrice: Number
promoStart: String
promoEnd: String
stockingPrice: Number
finalPrice: Number
isActiveProduct: Boolean
availableQuantity: Number
quantityUnit: String
category: String
saleType: String
manufactureCompany: String
year: String
color: String
tags: Array
variantID: String
description: String
}
Run Code Online (Sandbox Code Playgroud)
我检查了一下,发现数字的情况下有 ID 类型和 Float 类型。
但是,我正在编写 JavaScript。promoPrice 属性有可能会获得浮点数或整数,如果是这种情况,我不希望抛出错误。这就是为什么我想使用 Number 类型。
另外,如果数组同时包含字符串和数字,我该怎么办?
我需要将我的数据缓存在磁盘上以供离线查看,我在 apollo-ios 源中找到了 ApolloSQLite,但是我找不到 ApolloSQLite 的任何文档(我也尝试过谷歌搜索)。
环境:
Xcode 10.1
macOS 10.14.3
CocoaPods 1.5.3
Apollo (0.9.5)
SQLite.swift (0.11.5)
Run Code Online (Sandbox Code Playgroud)
之后出现太多错误pod install
:
pod 'Apollo'
pod 'Apollo/SQLite'
Run Code Online (Sandbox Code Playgroud)