Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/frantallukas10/graphql-fundamentals
https://github.com/frantallukas10/graphql-fundamentals
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/frantallukas10/graphql-fundamentals
- Owner: frantallukas10
- License: mit
- Created: 2019-12-03T06:17:26.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T02:21:30.000Z (about 2 years ago)
- Last Synced: 2024-11-18T21:59:45.790Z (2 months ago)
- Size: 5.19 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 43
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# graphql-fundamentals
![logo](./docs/advanced/images/logo.png)
GraphQL is bit like SQL, but for querying web APIs rather than databases. You can ask for what you need, get exactly that. Client has full control over which data it wants from the server. It resolves over fetching data. Graphql can get many resources in a single request, so that solves under fetching data. Automaticly generate describes your API. Graphql has powerful developer tool
- [graphql.js doc](https://graphql.org/graphql-js/)
- [graphql advantages vs disvantages](https://www.robinwieruch.de/why-graphql-advantages-disadvantages-alternatives#graphql-advantages)
- [graphql.js github repository](https://github.com/graphql/graphql-js)- [apollo.js doc](https://www.apollographql.com/docs)
- [Schemas and types for graphql](https://graphql.org/learn/schema)## Simple example of how to make a GraphQL request over HTTP.
- [./examples/simple/server/index.js](./examples/simple/server/index.js)
- [./examples/simple/client/index.html](./examples/simple/client/index.html)### Defining a schema
```js
const { gql } = require('apollo-server');const typeDefs = gql`
type Query {
greeting: String
}
`;console.log(typeDefs);
```console output:
```js
{ kind: 'Document',
definitions:
[ { kind: 'ObjectTypeDefinition',
description: undefined,
name: [Object],
interfaces: [],
directives: [],
fields: [Array] } ],
loc: { start: 0, end: 41 } }
```This object represents an abstract syntax tree of the Graphql.
### Implementing resolver functions
be careful! for `new ApolloServer()` you can define only a configuration object with our `typeDefs` and `resolvers`.
```js
const resolvers = {
Query: {
greeting: () => 'Hello GraphQl World!'
}
};const server = new ApolloServer({ typeDefs, resolvers });
server
.listen({ port: 9000 })
.then(serverInfo =>
console.log(
`Server running at ${serverInfo.url}`,
`\n${JSON.stringify(serverInfo)}`
)
);
```### ServerInfo argument return object with properties:
```js
{
"address": "::",
"family": "IPv6",
"port": 9000,
"server": {
"_events": {},
"_eventsCount": 5,
"_connections": 0,
"_handle": {
"reading": false,
"onread": null
},
"_usingWorkers": false,
"_workers": [],
"_unref": false,
"allowHalfOpen": true,
"pauseOnConnect": false,
"httpAllowHalfOpen": false,
"timeout": 120000,
"keepAliveTimeout": 5000,
"maxHeadersCount": null,
"headersTimeout": 40000,
"_connectionKey": "6::::9000"
},
"subscriptionsPath": "/graphql",
"url": "http://localhost:9000/",
"subscriptionsUrl": "ws://localhost:9000/graphql"
}
```
- [Advanced example](./docs/advanced/intro.md)