如何解决WSO2 上的自省 GraphQL
我们在 WSO2 中有一个 GraphQL API,我们有一个使用此 API 的前端 Web 项目。在运行前端项目之前,我们在终端上输入 yarn graphql:codegen
命令,这样我们就可以使用环境变量中的服务端点生成我们的 graphql 模式。当我们直接使用我们的服务端点时,它可以生成架构。
但是,如果我们使用网关端点(在 WSO2 中生成)并输入相同的命令,我们将无法从此 URL 加载架构。我们看到了这个错误。
Failed to load schema from https://gateway.staging.XXXXXXX.XXXXXXX/XXXXXX/1.0.0/graphql:
Could not obtain introspection result,received: {"Fault":{"faultcode":"soapenv:Server","faultstring":"class graphql.language.FragmentSpread cannot be cast to class graphql.language.Field (graphql.language.FragmentSpread and gr
aphql.language.Field are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @78c1a8e6)","detail":null}}
Error: Could not obtain introspection result,"faultstring":"class graphql.language.FragmentSpread cannot be cast to class graphql.language.Field (graphql.language.FragmentSpread
and graphql.language.Field are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @78c1a8e6)","detail":null}}
at getSchemaFromIntrospection (C:\Users\wic\web\node_modules\@graphql-tools\wrap\index.cjs.js:1766:15)
at C:\Users\wic\web\node_modules\@graphql-tools\wrap\index.cjs.js:1776:58
at processticksAndRejections (internal/process/task_queues.js:93:5)
at async UrlLoader.getSubschemaConfigAsync (C:\Users\wic\web\node_modules\@graphql-tools\url-loader\index.cjs.js:333:21)
at async UrlLoader.load (C:\Users\wic\web\node_modules\@graphql-tools\url-loader\index.cjs.js:386:33)
at async loadFile (C:\Users\wic\web\node_modules\@graphql-tools\load\index.cjs.js:48:37)
at async C:\Users\wic\web\node_modules\@graphql-tools\load\index.cjs.js:426:24
GraphQL Code Generator supports:
- ES Modules and Commonjs exports (export as default or named export "schema")
- Introspection JSON File
- URL of GraphQL endpoint
- Multiple files with type deFinitions (glob expression)
- String in config file
Try to use one of above options and run codegen again.
Error: Failed to load schema
at loadSchema (C:\Users\wic\web\node_modules\@graphql-codegen\cli\bin.js:461:15)
at processticksAndRejections (internal/process/task_queues.js:93:5)
at async C:\Users\wic\web\node_modules\@graphql-codegen\cli\bin.js:874:55
at async Task.task (C:\Users\wic\web\node_modules\@graphql-codegen\cli\bin.js:727:17)
Error: Failed to load schema
at loadSchema (C:\Users\wic\web\node_modules\@graphql-codegen\cli\bin.js:461:15)
at processticksAndRejections (internal/process/task_queues.js:93:5)
at async C:\Users\wic\web\node_modules\@graphql-codegen\cli\bin.js:874:55
at async Task.task (C:\Users\wic\web\node_modules\@graphql-codegen\cli\bin.js:727:17)
我们尝试使用网关端点在 Postman 中发送查询,并且我们正在使用认知授权。效果很好。
我怀疑这个问题是关于内省的。但是我没有找到 WSO2 的任何解决方案。我试图通过检查页面来获取 WSO2 Devportal 中“下载架构”按钮的直接 URL,但它没有提供任何 URL。
我该如何解决问题?
解决方法
您可以使用 APIM 3.2.0 中的 REST API 获取 API 的 GraphQL 架构。
在这里,您必须提供 apiId
作为路径参数。
例如:
curl -k -H "Authorization: Bearer <access_token>" "https://<hostname>/api/am/publisher/v1/apis/<apiId>/graphql-schema"
有关 APIM Publisher REST API 入门的更多信息,请参阅 this。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。