1.0.8 • Published 9 months ago

@edurata/amplify-graphql-type-simplify v1.0.8

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

@edurata/amplify-graphql-type-simplify

Converts Graphql queries and mutations generated by AWS Amplify to a ready-to-use fully-typed function SDK.


Sample SDK usage

Lists all available queries and mutations

image

Auto detects variables associated to selected query/mutation

image


Setup

This tool requires a working AWS Amplify project using typescript. There should be a .graphqlconfig.yml file in root directory.

projects:
  edurata:
    schemaPath: /src/graphql/schema.json
    includes:
      - src/graphql/**/*.ts
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: typescript
        generatedFileName: src/graphql/api.ts
        docsFilePath: src/graphql
        region: us-west-1
        apiId: null
        maxDepth: 4
      ## Add this additional extension
      apiRequest:
        generatedFileName: src/graphql/apiRequest.ts
    ## ##
extensions:
  amplify:
    version: 3

To generate SDK file, run this in amplify root directory:

amplify api gql-compile && amplify codegen && npx @edurata/amplify-graphql-type-simplify --yes

Setup for Amplify Graphql API

import { API, graphqlOperation } from "aws-amplify";
import { setHandler } from "graphql/apiRequest"; // generate apiRequest sdk

export default function configureAppSyncRequest() {
  setHandler(async (query, variables) => {
    try {
      const response = await API.graphql(graphqlOperation(query, variables));
      return response;
    } catch (err) {
      return { errors: [err] };
    }
  });
}
1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

10 months ago

1.0.4

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.0.5

1 year ago