All Projects → theGlenn → Apollo Prophecy

theGlenn / Apollo Prophecy

Licence: mit
🔮 GraphQL error management made Easy, generate custom machine-readable errors for Apollo Client/Server from the CLI

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Apollo Prophecy

React Fullstack Graphql
Starter projects for fullstack applications based on React & GraphQL.
Stars: ✭ 1,352 (+1528.92%)
Mutual labels:  graphql, apollo, apollographql
Fraql
GraphQL fragments made simple ⚡️
Stars: ✭ 433 (+421.69%)
Mutual labels:  graphql, apollo, apollographql
React Graphql Github Apollo
🚀 A React + Apollo + GraphQL GitHub Client. Your opportunity to learn about these technologies in a real world application.
Stars: ✭ 1,563 (+1783.13%)
Mutual labels:  graphql, apollo, apollographql
Graphback
Graphback - Out of the box GraphQL server and client
Stars: ✭ 323 (+289.16%)
Mutual labels:  graphql, apollo, apollographql
Apollo Mocked Provider
Automatically mock GraphQL data with a mocked ApolloProvider
Stars: ✭ 70 (-15.66%)
Mutual labels:  graphql, apollo, apollographql
Booben
Web app constructor based on React, with GraphQL bindings
Stars: ✭ 96 (+15.66%)
Mutual labels:  graphql, apollo, apollographql
Graphql Up
Get a ready-to-use GraphQL API for your schema
Stars: ✭ 415 (+400%)
Mutual labels:  graphql, apollo, apollographql
Angular Fullstack Graphql
🚀 Starter projects for fullstack applications based on Angular & GraphQL.
Stars: ✭ 92 (+10.84%)
Mutual labels:  graphql, apollo, apollographql
Offix
GraphQL Offline Client and Server
Stars: ✭ 694 (+736.14%)
Mutual labels:  graphql, apollo, apollographql
Learnapollo
👩🏻‍🏫 Learn Apollo - A hands-on tutorial for Apollo GraphQL Client (created by Graphcool)
Stars: ✭ 5,274 (+6254.22%)
Mutual labels:  graphql, apollo, apollographql
Get Graphql Schema
Fetch and print the GraphQL schema from a GraphQL HTTP endpoint. (Can be used for Relay Modern.)
Stars: ✭ 443 (+433.73%)
Mutual labels:  graphql, apollo, apollographql
Graphql React Apollo
A GraphQL implementation in React using Apollo.
Stars: ✭ 9 (-89.16%)
Mutual labels:  graphql, apollo, apollographql
Graphql
GraphQL (TypeScript) module for Nest framework (node.js) 🍷
Stars: ✭ 697 (+739.76%)
Mutual labels:  graphql, apollo, apollographql
Link state demo
🚀 Demonstrate how to support multiple stores in Apollo Link State
Stars: ✭ 30 (-63.86%)
Mutual labels:  graphql, apollo, apollographql
Blaze Apollo
Blaze integration for the Apollo Client
Stars: ✭ 56 (-32.53%)
Mutual labels:  graphql, apollo
Subscriptions Transport Sse
A Server-Side-Events (SSE) client + server for GraphQL subscriptions
Stars: ✭ 55 (-33.73%)
Mutual labels:  graphql, apollo
Erxes Api
API for erxes
Stars: ✭ 57 (-31.33%)
Mutual labels:  graphql, apollo
Guide To Graphql
A Frontend Developer's Guide to GraphQL (Fluent Conf 2018)
Stars: ✭ 59 (-28.92%)
Mutual labels:  graphql, apollo
Apollo Cache Persist
🎏 Simple persistence for all Apollo Cache implementations
Stars: ✭ 1,078 (+1198.8%)
Mutual labels:  graphql, apollo
Next React Graphql Apollo boostrap
React + GraphQL + Next.js project architecture that I play with right now
Stars: ✭ 59 (-28.92%)
Mutual labels:  graphql, apollo

Apollo Prophecy

👁📟👁
You shall fail... successfully
Command tool to generate errors files for your Appolo Server and Client

📟 Features

  • Generate Server-side throwable errors in your resolvers like throw new NotAProphetError()
  • Expose machine readable graphql errors through your api documentation
  • Generate Client-side Apollo errors consumable like errorHere(error).isNotAProphetError ?

📋 Table of Contents

Installation

Install with npm:

npm install -g apollo-prophecy

Install with yarn:

yarn global add apollo-prophecy

Usage

Usage: apollo-prophecy [command]

Commands:
  apollo-prophecy generate <json file> [--out]
  apollo-prophecy ask <graphql endpoint> [--type] [--out]

Options:
  -h, --help     Show help                                             [boolean]
  -v, --version  Display version number                                [boolean]

Server

⚠️ This Project is Only compatible with Apollo-Server v2

generate command

Creates Error.ts from a JSON input file. Using --out param you can change the name and location.

apollo-prophecy generate errors.json

Input file entries should at least contains the keys message and code.

For example given the following errors.json as input:

{
  "AuthenticationRequiredError": {
    "message": "You must be logged in to do this",
    "code": "AUTH_REQUIRED"
  },
  "UserNotFoundError": {
    "message": "No user found",
    "code": "USER_NOT_FOUND"
  },
}

Apollo Prophecy will generate the following Errors.ts

...
export class AuthenticationRequiredError extends ProphecyError {
  constructor(properties?: Record<string, any>) {
    super("AuthenticationRequiredError", "You must be logged in to do this","AUTH_REQUIRED", properties);
  }
}
  
export class UserNotFoundError extends ProphecyError {
  constructor(properties?: Record<string, any>) {
    super("UserNotFoundError", "No user found", "USER_NOT_FOUND", properties);
  }
}
...

Now you can use it the following way throw new UserNotFoundError() in your resolvers.

apollo-prophecy also exposes a definitions object and a graphql type definition named PropheticError so that you can expose all your errors descriptions through a resolver, see Client.

...
export const definitions = [{
    "name": "AuthenticationRequiredError"
    "message": "You must be logged in to do this",
    "extensions": {
      "code": "AUTH_REQUIRED"
    }
  }, {
    "name": "UserNotFoundError"
    "message": "No user found",
    "extensions": {
      "code": "USER_NOT_FOUND"
    }
  }
}];

export const errorType = `
  type PropheticErrorExtensions {
    code: String
  }

  type PropheticError {
    message: String?
    extensions: PropheticErrorExtensions
  }
`;
...

Client

ask command

Queries the errors field on the specified graphql endpoint and creates an Errors.ts file containing helpers with check methods (see Helpers) for all the errors exposed through the server api documentation.

apollo-prophecy ask http://localhost:3000/graphql

Helpers

In order to easily handle erros with Apollo-Client, the generated Errors.ts exposes two helpers methods errorHere and isThis, both methods takes one paramater of type ApolloError or GraphQLError.

errorHere() function

errorHere returns an object that has a property named after each errors. You can perform a simple boolean check on the error argument by calling the approiate key.

import { errorHere } from `./_generated/Errors.ts`;

...(error) => {
  if(errorHere(error).isUserNotFoundError){
    // Do something
  } else if(errorHere(error).isNotAProphetError){
    // Do something else
  }
}
isThis() function

isThis returns an object that has a handler method for each errors. It perfoms a simple check on the error argument, if the it succeed the corresponding handler is called otherwise nothing happens.

Note: Handlers can return a values.

import { isThis } from `./_generated/Errors.ts`;

...(error) => {
  isThis(error)
  .UserNotFoundError(() => ...)
  .NotAProphetError(() => ...)
  .handle()
}

React example:

import { isThis } from `./_generated/Errors.ts`;

...(error) => {
  return <p style={{color: '#FF495C'}}>
    {
      isThis(error)
      .UserNotFoundError(() => <span>Could not find a user with tha name</span>)
      .NotAProphetError(() => <span>Only Prophets can perfom this kind of actions...</span>)
      .handle();
    }
  </p>
}

Contributing

Build status

Grab an issue
🍴 fork develop
👨‍💻 Code
🛠 Test
📩 Pull Request

💥💥💥

TODO

Run tests

npm test
yarn test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].