WSO2 上的自省 GraphQL
Introspection GraphQL on WSO2
我们在 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, received: {"Fault":{"faultcode":"soapenv:Server","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 中发送查询,我们还使用了认知授权。效果不错。
我怀疑这个问题是关于Introspection的。但是我没有找到 WSO2 的任何解决方案。我试图通过检查页面直接获得 WSO2 Devportal 中“下载模式”按钮的 URL,但它没有提供任何 URL。
我该如何解决这个问题?
我们在 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, received: {"Fault":{"faultcode":"soapenv:Server","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 中发送查询,我们还使用了认知授权。效果不错。
我怀疑这个问题是关于Introspection的。但是我没有找到 WSO2 的任何解决方案。我试图通过检查页面直接获得 WSO2 Devportal 中“下载模式”按钮的 URL,但它没有提供任何 URL。
我该如何解决这个问题?