GitXplorerGitXplorer
b

snap-templates

public
2 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
fcba03808a5b06141bebfef6071e532326c1643a

spelling fix

committed 7 years ago
Verified
879140bbc26d0f18815fa9f49d7fddb24983d1f9

Merge pull request #2 from brianfitzgerald/clients

bbrianfitzgerald committed 7 years ago
Unverified
3219b59a5aa919de174383734640a758dbeec8db

merge master

committed 7 years ago
Unverified
ac5e353d43397f4fa48779856870e7e13ef1f090

cleanup

committed 7 years ago
Unverified
1319c7f1010c9a3963ea4d853bd5c2a360e70f34

request working

committed 7 years ago
Unverified
6ba3ef7df1277b5bde29b5fb3c545d82860b2f90

more work

committed 7 years ago

README

The README file for this repository.

Snap

screens

Easily integrate the following services with GraphQL, without having to write resolvers:

  • DynamoDB
  • AWS Lambda
  • MongoDB
  • JSON

And easily add more.

Resolver Mapping Templates

Getting Started

npm i snap-templates

Code Samples

const app = express()

const schema = buildSchema(`
  type Song {
    id: String
    SpotifyURL: String
    Genre: String
  }
  type Query {
    song(id: Int): Song
  }
`)

const mappingTemplate: MappingConfiguration = {
  songByGenre: {
    kind: "DynamoDB",
    operation: "Scan",
    query: {
      TableName: "ambliss-songs",
      FilterExpression: "genre = :genre",
      ExpressionAttributeValues: {
        ":genre": {
          S: "$context.arguments.genre"
        }
      }
    }
  }
}

app.use(
  "/graphql",
  graphqlHTTP({
    schema: schema,
    rootValue: buildResolver(mappingTemplate),
    graphiql: true
  })
)

API Overview

buildResolver(mappingTemplate: MappingConfiguration, clients: ClientMapping): ResolverMapping

This is the main way you implement Snap. It accepts an object whose keys are the mappings from your data sources to a GraphQL query. The function returns a mapping of GraphQL resolvers, that can be consumed as the rootValue of GraphQL Express.

Mapping Templates

Templates

type DynamoQueryTemplate = {
    kind: "DynamoDB"
    operation: "GetItem" | "Query"
    query: DynamoDB.Types.GetItemInput | DynamoDB.Types.QueryInput
}
type LambdaQueryTemplate = {
    kind: "Lambda"
    FunctionName: string
}