Git Product home page Git Product logo

www-template's Introduction

www-template

CircleCI Commitizen friendly CodeFactor

Development

Clone the repository and run:

# install dependencies
yarn

# start development server
yarn dev

The development runs both the Express server and the Webpack devServer concurrently, proxying the Express server to port 3001. Go to http://localhost:3000 to view the application.

Any changes to server-side code will restart the server (via nodemon) and any changes to client-side code will auto-change on the browser (via react-refresh.)

GraphQL

Modules

We use GraphQL Modules in order to separate the GraphQL schema implementation into small, reusable, easy-to-implement and easy-to-test pieces with the possibility to extract them easily if necessary in the future.

Each module is made up of a schema, resolvers and their datasource which makes the relevant calls to external apis.

In order to correctly type the resolvers, once the schema has changed, run yarn generate to create typings for the module.

Apollo Server

The modules are collated in src/server/graphql/index and passed to an instance of Apollo Server. When this server is started (as part of the overall Express server) the GraphQL playground is available in dev environment at /graphql.

Apollo Client (Server)

The server-side instance of Apollo Client is initiated in src/server/routes/application. Using SchemaLink allows performing GraphQL operations on the provided schema rather than making network calls when loading the page.

Apollo Client (Browser)

The client-side instance of Apollo Client is initiated in src/client/index. The client is initiated with the value of window.__APOLLO_STATE__ which is passed to the html via src/server/routes/application.

Queries

Queries are made within React components as and when they are required. For example:

const GET_ME = gql`
  query me {
    me {
      firstName
    }
  }
`;

This query knows which resolver query to call and we want just the firstName to be returned. We call that query within the React component:

const { error, loading, data } = useQuery(GET_ME);

if (loading) return <p>Loading...</p>;
if (error) return <p>Error :(</p>;

return <p>{data.me.firstName}</p>

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.