Coder Social home page Coder Social logo

stepzen-dev / snippets Goto Github PK

View Code? Open in Web Editor NEW
20.0 1.0 3.0 224 KB

Snippets for securing, transforming, and optimizing GraphQL APIs.

Home Page: https://stepzen.com/

License: MIT License

JavaScript 100.00%
graphql graphql-server stepzen graphql-api graphql-schema graphql-schema-generator graphql-schema-language graphql-schemas security

snippets's Introduction


Logo

StepZen Snippets

Welcome! StepZen is a unique and declarative way to build & run any-sized Graph in minutes.

Table of Contents
  1. About The Project
  2. `@transforms`
  3. `@sequence`
  4. protection
  5. `@rest` calls and responses

About the project

This repo contains .graphql (and in some case, config.yaml files) for various "self-contained" example code for doing operations in StepZen.

Getting Started

Install the StepZen command line interface.

To run these examples,

  • git clone this repo
  • Change to the right working directory.
  • run stepzen start

transforms

For more on what transforms is and how it operates within the custom @rest directive, see our documentation.

These are available in /transforms:

  • /filter shows how the response of a REST API can be filtered
  • /combineintostring shows how a new field in the return type can be created by concatenating some other fields (like address parts into one address)
  • /jsonobjectToJsonarray shows how an array of data (say coords) can be converted into an object, {"lat":, "lon",..} so that it can be fed into some other system that requires data to be expressed that way
  • /jsonobjectToJsonarray shows how an object (typically where each key is an id of a record) can be converted into an array (e.g., {"1":{"name": "john"}, "2": "jane"} can be converted to [{"id":"1", "name": "john"}, {"id":"2", name: "jane"}]), so that it can then behave well for GraphQL processing.

@sequence

View the StepZen documentation on the custom directive @sequence.

These are available in /sequence:

  • /arguments shows how query arguments get passed down a sequence
  • /forLoops shows how sequence acts as a nested for loop
  • /transformsInMaterializer shows how connecting two subgraphs can invoke transformations in between. For example, the city of a customer can be fed into a weather that takes lat,lon by calling some geocoding in the sequence
  • /useOfJSON shows how, in long sequences, a new type does not have to created for every step--treat everything as JSON up to the last step, and your type system stays clean.

@dbquery

View the documentation for the @dbquery custom directive in the documentation.

Uses a database filled with mock data.

  • /pagination shows how to implement connection model pagination for a database.

protection

For more information on protecting your API, see our documentation.

In /protection, you will find several subdirectories. Each contains a .graphql file, and index.graphql file and a config.yaml settings (which enables you to get extremely granular (or coarse) with protecting who can call what query/mutation).

  • /makeAllPublic shows how you can easily make all queries public.
  • /makeSomePublic shows how you can make some public, and some private (which can still be accessed using your admin or service keys)

@rest calls and responses

Where possible, we use httpbingo.org as our REST endpoint, since it allows us to mimic lots of REST capabilities.

  • /restWithParameters shows how GraphQL query arguments are automatically added to the REST call--there is nothing for you to do!
  • /restWithConfigYaml shows how REST query parameters can also be fetched from config.yaml--this allows you to keep your SDL code separate from your secrets.
  • /postbody shows how a POST body can be automatically filled with query arguments when the Content-Type:application/x-www-form-urlencoded. This is the easiest way to send postbodies down the REST API
  • /morecomplexpost shows how a POST body can be filled with query arguments using {{.Get \"name-of-query-argument\"}} when the Content-Type:application/x-www-form-urlencoded.

union types

Union types are valuable when you have a field that can return one of several types.

  • /errorsAsData shows how to implement the "errors as data" pattern. This is useful when you want to return a field that can return either a value or an error.

snippets's People

Contributors

bobbiejc avatar carloseberhardt avatar cerchie avatar ddebrunner avatar dependabot[bot] avatar jhingran avatar royderks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.