Giter VIP home page Giter VIP logo

pc-graphql's Introduction

pc-graphql

PoC for the Graphql API at Permission Click

Basic Concepts

The two most important pieces of a GraphQL server are the type definitions and the resolvers.

The types are declared in Schema Definition Language and are used as the "contract" between backend and frontend. The resolvers are functions that instruct the GraphQL server how to act when it receives a query or mutation.

Type Definitions

In this project, the type definitions are located in the src/schema.graphql file. They are also used to generate the src/types.ts file which provides TypeScript with the same types used by the GraphQL server. To do that run yarn generate. This way we have a single source of truth for the types in the server.

Resolvers

The resolvers are located in the src/resolvers folder. They are type safe functions that act like a "router" for the queries and mutations received by the server. Every query and every mutation needs its own resolver function. In this project specifically, the resolver functions map to functions in Models. (Temporary name, accepting better suggestions). These Models live on the src/models folder and their job is to house functions that call external API's or access databases and return the desired result for the query or mutation that originally called them.

This separation is completely optional. We could have resolver functions directly calling APIs, but by creating this middle step, we can reuse API methods and put business rules / validations on the models and make the resolver act just like routers to them. This makes the code easier to reuse and maintain.

Besides queries and mutations, specific fields can have their own resolver functions. As can be seen in the resolvers folder for DocumentVersion for example.

Data Access

This GraphQL server access data both directly from the database, and using REST APIs. This shows the flexibility of the GraphQL architecture and how it canimprove end user experience. The user can get all information it needs from a single request to the GraphQL server, that will then make all the requests necessary to compose the information that will be sent back.

Building and Starting the Server

From the root folder run yarn to install all the dependencies and then yarn start. This will start a the GraphQL server and also a GraphQL Playground on localhost:4000. On the GraphQL Playground you can write queries and mutations and run them against the server. Additionally, it provides access to the server's Schema containing all type definitions and auto generated Docs, containing information about what queries and mutations are available to be executed on this server, what arguments they take and what is the shape of the data that will be returned.

All this documentation is created automatically when the server instance starts.

Tests

TODO

RoadMap

  • Discuss implementation of the GraphQL layer over REST / Direct access to DB
  • Business logic
  • Authentication
  • Advanced cache (Redis / Azure...)
  • Discuss if can be run as Azure Function

pc-graphql's People

Contributors

filipemolina avatar

Watchers

 avatar James Cloos 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.