Giter Club home page Giter Club logo

angular-io-example-graphql's Introduction

Tour of Heroes with GraphQL

A copy of the final code for the Angular Tour of Heroes Tutorial (Part 6), but with minimal changes to support data storage on a real server-based relational database (and accessible via a GraphQL API).

As originally, the front-end is implemented using Angular and TypeScript, but this time with support from Apollo Client for communicating with the server using GraphQL, and (the extraordinarily powerful, but still in Alpha) PostGraphile for providing a GraphQL API on the server. A suitable database definition (and sample data) is provided in a SQL script (toh.pgsql).

Prerequisites

  • install Node.js
  • install PostgreSQL
  • optionally install a good IDE with TypeScript support, e.g. VS Code
  • optionally install Yarn (rather than using NPM)

Example installation

  • clone the repository git clone https://github.com/tjme/angular-io-example-graphql.git toh-graphql
  • change to your project directory cd toh-graphql
  • create/configure a PostgreSQL "toh" database sudo -u postgres psql -d template1, then enter the following SQL commands:
CREATE USER test WITH PASSWORD 'testpass';
\c toh
\i toh.pgsql
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO test;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO test;
\q
  • install PostGraphile globally yarn global add postgraphile (or npm -g i postgraphile)
  • optionally generate JSON and GraphQL schema files postgraphile -c postgres://test:testpass@/toh -s public --export-schema-json toh.json --export-schema-graphql toh.gql
  • run the GraphQL server (in the background) with postgraphile -c postgres://test:testpass@/toh -s public -o &
  • optionally you can click on the link to GraphiQL generated by the above, and explore the server by entering queries such as: {allHeroes{nodes{nodeId,id,name}}}
  • install angular CLI globally (you may need elevated privileges, e.g. prefix with sudo) yarn global add @angular/cli
  • if using yarn, configure ng set --global packageManager=yarn
  • install the front-end dependencies with yarn (or npm i)
  • run the Angular server ng serve --open
  • Tour of Heroes should open automatically in your browser, and you should be able to list, add, update and delete heroes that are then stored (persistently) in the database
  • you can restore the database, with its initial sample data, by re-running the toh.pgsql script

Issues

Currently, the Apollo-Angular can only return immutable Observables (see apollo-angular/#306), so a small code change was necessary in hero-detail-component.ts.

Any feedback would be gratefully recieved!

Thanks, [email protected]

angular-io-example-graphql's People

Contributors

tjme avatar

Stargazers

 avatar  avatar  avatar  avatar

angular-io-example-graphql's Issues

Heroes list not always automatically updated

The list is not updated after adding a new hero, unless one has been deleted (and the browser has not been refreshed since).

Note that updates however, are reflected on the dashboard, as well as deletes on the heroes list.

webpack fails to compile with ng serve

I tried to get this to work (newbie), but ran into this.

STEPS

npm install
ng serve

RESULTS

ERROR in node_modules/apollo-cache-inmemory/lib/inMemoryCache.d.ts(17,26): error TS1110: Type expected.
node_modules/apollo-cache-inmemory/lib/inMemoryCache.d.ts(17,33): error TS1138: Parameter declaration expected.
node_modules/apollo-cache-inmemory/lib/inMemoryCache.d.ts(17,42): error TS1005: ';' expected.
node_modules/apollo-cache-inmemory/lib/inMemoryCache.d.ts(17,43): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,62): error TS1005: ';' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,77): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,88): error TS1005: ';' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,103): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,112): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,127): error TS1005: ';' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,142): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,151): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,160): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,179): error TS1005: ';' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,194): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,203): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,212): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,221): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,244): error TS1005: ';' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,259): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,268): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,277): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,286): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,295): error TS1005: ',' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,322): error TS1005: ';' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,337): error TS1005: ')' expected.
node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(1,338): error TS1005: ';' expected.
node_modules/graphql-tag/index.d.ts(5,6): error TS1110: Type expected.
node_modules/optimism/lib/context.d.ts(4,17): error TS1110: Type expected.
node_modules/optimism/lib/context.d.ts(4,24): error TS1138: Parameter declaration expected.
node_modules/optimism/lib/context.d.ts(4,33): error TS1005: ',' expected.
node_modules/optimism/lib/context.d.ts(4,34): error TS1134: Variable declaration expected.
node_modules/optimism/lib/context.d.ts(4,40): error TS1005: '=' expected.
node_modules/optimism/lib/context.d.ts(4,44): error TS1005: '>' expected.
node_modules/optimism/lib/context.d.ts(4,49): error TS1005: '=' expected.
node_modules/optimism/lib/context.d.ts(4,51): error TS1109: Expression expected.
node_modules/optimism/lib/context.d.ts(5,30): error TS1005: ';' expected.
node_modules/optimism/lib/context.d.ts(5,63): error TS1005: ')' expected.
node_modules/optimism/lib/context.d.ts(5,98): error TS1109: Expression expected.
node_modules/optimism/lib/context.d.ts(5,108): error TS1005: ';' expected.
node_modules/optimism/lib/context.d.ts(5,115): error TS1005: ')' expected.
node_modules/optimism/lib/context.d.ts(5,124): error TS1109: Expression expected.
node_modules/optimism/lib/context.d.ts(5,138): error TS1005: ';' expected.
node_modules/optimism/lib/context.d.ts(5,140): error TS1128: Declaration or statement expected.
node_modules/optimism/lib/context.d.ts(5,157): error TS1109: Expression expected.
node_modules/optimism/lib/context.d.ts(5,186): error TS1109: Expression expected.
node_modules/optimism/lib/context.d.ts(5,205): error TS1005: ';' expected.
node_modules/optimism/lib/context.d.ts(5,206): error TS1128: Declaration or statement expected.
node_modules/optimism/lib/context.d.ts(6,1): error TS1128: Declaration or statement expected.

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.