Graphql WSO2上的内省图QL

Graphql WSO2上的内省图QL,graphql,wso2,wso2-am,introspection,Graphql,Wso2,Wso2 Am,Introspection,我们在WSO2中有一个GraphQLAPI,我们有一个使用此API的前端web项目。在运行前端项目之前,我们在终端上输入graphql:codegen命令,这样我们就可以通过使用环境变量中的服务端点来生成graphql模式。当我们直接使用服务端点时,它可以生成模式 但是,如果使用网关端点(在WSO2中生成)并输入相同的命令,则无法从该URL加载模式。我们看到了这个错误 Failed to load schema from https://gateway.staging.XXXXXXX.X

我们在WSO2中有一个GraphQLAPI,我们有一个使用此API的前端web项目。在运行前端项目之前,我们在终端上输入
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中执行发送查询,并且我们正在使用cognito授权。它工作得很好

我怀疑这个问题与内省有关。但我没有找到任何解决WSO2的方法。我试图通过检查页面来获取WSO2 Devportal中“下载模式”按钮的直接URL,但它没有给出任何URL


如何解决这个问题?

您可以使用APIM 3.2.0中的获取API的GraphQL模式

这里,您必须提供
apid
作为路径参数。 例如:


curl-k-H”Authorization:Bearer了解有关APIM Publisher REST API入门的更多信息。

太棒了,谢谢。这适用于我的
.graphql
文件。schema.json呢?有什么解决方案可以创建它吗?你是说普通的招摇过市定义吗?可以使用REST API获得它。
curl -k -H "Authorization: Bearer <access_token>" "https://<hostname>/api/am/publisher/v1/apis/<apiId>/graphql-schema"