Commit 6fe392ae authored by alexlbr's avatar alexlbr

initial commit

parents
{
"presets": []
}
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules
jspm_packages
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history
#graphql generated data
data
#build
dist/
# Thinking in GraphQL exercise
This exercise is part of the [React GraphQL Academy](http://reactgraphql.academy) learning material. The goal of the exercise is to help you get started transitioning from REST to GraphQL.
## Learning objectives
- Thinking in Graphs
- Learn how to connect resolvers to a REST API
- Understand Schema Design principles
## Exercise part 1
[https://rickandmortyapi.com/graphql/](https://rickandmortyapi.com/graphql/)
- Query a list of characters are in the system
- Query a list with all the character names
- Query how many characters are in the system
- Query a single characther by id (try id equals 1) and get its name
- How many currencies in the system?
- How many types do we have in the system?
## Exercise part 2
### To get started
We are going to create our own GraphQL API on top of this [Rick and Morty API](https://rickandmortyapi.com/documentation/#rest)
- `git clone git@github.com:reactgraphqlacademy/rest-to-graphql-workshop.git`
- `cd rest-to-graphql-workshop`
- `yarn install` or `npm install`
- `yarn start` or `npm start`
- [ ] 1. Create a Character type in your schema. Here is the [documentation of the character endpont](https://rickandmortyapi.com/documentation/#character-schema).
- [ ] 2. Create as Episode type in your schema. Here is the [documentation of the episode endpont](https://rickandmortyapi.com/documentation/#episode-schema).
### Bonus exercise
## Articles and links
- http://graphql.org/learn/
- http://graphql.org/learn/thinking-in-graphs/
- https://dev-blog.apollodata.com/graphql-vs-rest-5d425123e34b
- https://dev-blog.apollodata.com/graphql-explained-5844742f195e
- https://facebook.github.io/relay/docs/thinking-in-graphql.html
- https://dev-blog.apollodata.com/the-anatomy-of-a-graphql-query-6dffa9e9e747
- https://github.com/apollographql/apollo-server
- https://www.youtube.com/watch?v=PHabPhgRUuU
- https://facebook.github.io/relay/graphql/connections.htm
- https://dev-blog.apollodata.com/introducing-launchpad-the-graphql-server-demo-platform-cc4e7481fcba
- https://dev-blog.apollodata.com/
- http://dev.apollodata.com
- https://astexplorer.net/
## License
This material is available for private, non-commercial use under the [GPL version 3](http://www.gnu.org/licenses/gpl-3.0-standalone.html).
{
"name": "rest-to-graphql-workshop",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "node_modules/.bin/nodemon src/index.js",
"start-babel": "node_modules/.bin/nodemon -- node_modules/.bin/babel-node src/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/reactgraphqlacademy/rest-to-graphql-workshop.git"
},
"author": "React Graphql Academy",
"license": "GPL version 3",
"bugs": {
"url": "https://github.com/reactgraphqlacademy/rest-to-graphql-workshop/issues"
},
"homepage": "https://github.com/reactgraphqlacademy/rest-to-graphql-workshop#readme",
"dependencies": {
"apollo-server": "^2.5.0",
"graphql": "^14.3.1"
},
"devDependencies": {
"@babel/core": "^7.4.5",
"@babel/node": "^7.4.5",
"nodemon": "^1.19.1"
}
}
const { ApolloServer, gql } = require("apollo-server");
// import { ApolloServer, gql } from "apollo-server";
// This is a (sample) collection of books we'll be able to query
// the GraphQL server for. A more complete example might fetch
// from an existing data source like a REST API or database.
const characters = [
{
name: "Rick Sanchez",
id: 1,
status: "Alive"
},
{
name: "Morty Smith",
id: 2,
status: "Alive"
}
];
// Type definitions define the "shape" of your data and specify
// which ways the data can be fetched from the GraphQL server.
const typeDefs = gql`
# Comments in GraphQL are defined with the hash (#) symbol.
# This "Characher" type can be used in other type declarations.
type Characher {
id: Int
name: String
status: String
}
type Episode {
id: Int
name: String
episode: String
}
# The "Query" type is the root of all GraphQL queries.
# (A "Mutation" type will be covered later on.)
type Query {
characters: [Characher]
episodes: [Episodes]
}
`;
// Resolvers define the technique for fetching the types in the
// schema. We'll retrieve books from the "books" array above.
const resolvers = {
Query: {
characters: () => characters
}
};
// In the most basic sense, the ApolloServer can be started
// by passing type definitions (typeDefs) and the resolvers
// responsible for fetching the data for those types.
const server = new ApolloServer({ typeDefs, resolvers });
// This `listen` method launches a web-server. Existing apps
// can utilize middleware options, which we'll discuss later.
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment