I'm having trouble writing the correct GraphQL query in Node.JS for an AWS DataExchange Provider's API specification

0

I'm trying to write a GraphQL query to fetch data from an AWS DataExchange provider based on their company's API specification.

However, every query I've written so far is returning 'data: null'.

I've verified that all my AWS credentials and IAM keys are correct.

Could someone please help me write the correct query based on the API specification given by the data provider.

Thanks!

My current request 'body' looks like below:


Body: JSON.stringify({
  content: {
      "application/graphql": {
        "schema": {
          "$ref": "#/components/schemas/CatalogSearchRequest"
        },
        query: `query availablemetadatarecord(limit: 10 content: { catalogProperties: { vendor: { eq: "EYE" } } }) {
                 assignedId
        }
      }`
      }
  }
}),

The DataExchange provider's actual API specification looks like below.


{
  "openapi": "3.0.1",
  "info": {
    "title": "image-services",
    "description": "API Gateway for integration of Platform Services into AWS Data Exchange",
    "version": "2022-03-03T20:04:18Z"
  },
  "servers": [
    {
      "url": ""
    }
  ],
  "paths": {
    "/psdm/graphql": {
      "post": {
        "requestBody": {
          "description": "GraphQL query for the Catalog in the form of:\n\n  `{\n    availablemetadatarecord(\n      QUERYPARAMS\n    ) { \n      FIELDLIST\n    } \n  }`\n",
          "content": {
            "application/graphql": {
              "schema": {
                "$ref": "#/components/schemas/CatalogSearchRequest"
              },
              "examples": {
                "Limit returned data": {
                  "description": "Limit the number of records in a response.\n\nIn your query, simply specify `limit: <int>` \n",
                  "value": "{\n  availablemetadatarecord(\n    limit: 10\n    content: { catalogProperties: { vendor: { eq: \"EYE\" } } }\n  ) {\n    assignedId\n  }\n}\n"
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CatalogSearchResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "sigv4": []
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "CatalogSearchRequest": {
        "title": "CatalogSearchRequest",
        "type": "object"
      },
      "CatalogSearchResponse": {
        "title": "Catalog Search Response",
        "required": [
          "data",
          "paginationInfo"
        ],
        "type": "object",
        "properties": {
          "paginationInfo": {
            "type": "object",
            "properties": {
              "recordsInPage": {
                "type": "integer"
              },
              "nextOffset": {
                "type": "integer"
              }
            }
          },
          "data": {
            "type": "object",
            "properties": {
              "availablemetadatarecord": {
                "type": "array",
                "description": "Records returned by query",
                "items": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "securitySchemes": {
      "sigv4": {
        "type": "apiKey",
        "name": "Authorization",
        "in": "header",
        "x-amazon-apigateway-authtype": "awsSigv4"
      }
    }
  }
}

The response I get from my GraphQL query looks like below:


httpRequest: HttpRequest {
    method: 'POST',
    path: '/',
    headers: { 'User-Agent': 'aws-sdk-nodejs/2.1241.0 win32/v16.9.1' },
    body: '',
    endpoint: {
      protocol: 'https:',
      host: 'dataexchange.us-east-1.amazonaws.com',
      port: 443,
      hostname: 'dataexchange.us-east-1.amazonaws.com',
      pathname: '/',
      path: '/',
      href: 'https://dataexchange.us-east-1.amazonaws.com/',
      constructor: [Function]
    },
    region: 'us-east-1',
    _userAgent: 'aws-sdk-nodejs/2.1241.0 win32/v16.9.1'
  },
  startTime: 2022-11-04T18:25:22.763Z,
  response: Response {
    request: [Circular *1],
    data: null,
    error: null,
    retryCount: 0,
    redirectCount: 0,
    httpResponse: HttpResponse {
      statusCode: undefined,
      headers: {},
      body: undefined,
      streaming: false,
      stream: null
    },
    maxRetries: 3,
    maxRedirects: 10
  },
  • It's hard to know what's going on without a subscription to whichever provider's API you're using, but I'll point out that the query you have in your body has an unbalanced number of curly braces; there is one more closing brace than opening one. Looking at the example in the schema, there is an opening brace before availablemetadatarecord.

1 Risposta
0

I ran into this with a simple dynamo table. The solution was to edit the schema in the AppSync console and add resolvers. The template code was enough in my case to get the data flowing.

con risposta un anno fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande