SANS
GERARD
Spoken at 177 events in 39 countries
source: blog
// POST '/graphql'
{
hello
}
// response.data
{
"hello": "Hello world!"
}
schema {
query: Query
}
type Query {
hello: String
}
Types
Field
Field
Types
Superfast
Safe
Best
Tooling
De-coupled Storage
Collaborative
DEVELOPMENT
PRODUCTION
DEVELOPMENT
PRODUCTION
Analytics
Performance
Logging
Default values
Validation
Caching
Authorisation
Data Formatting
SDL
GQL
Client
GraphQL Server
query
mutation
subscription
Components
Parse
request
Validate
GraphQL Client
Execute
Resolvers
response
SDL
GQL
Client
GraphQL Server
query
mutation
subscription
Components
Parse
request
Validate
GraphQL Client
Execute
Resolvers
response
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone'
const server = new ApolloServer({
typeDefs,
resolvers
});
const { url } = await startStandaloneServer(server);
console.log(`🚀 Server listening at: ${url}`); // port 4000
const typeDefs = `
schema {
query: Query
}
type Query {
hello: String
}
`;
const resolvers = {
Query: {
hello: async (parent, args, context, info) {
return "Hello world!";
},
},
};
curl -g \
-X POST \
-H "Content-Type: application/json" \
-d '{ "query": "query { hello }" }' \
https://pkff9q.sse.codesandbox.io/
{
"data": {
"hello":"Hello world"
}
}
query {
hello
}
Client
Server
GET
POST
PUT
PATCH
DELETE
request
response
400 BAD REQUEST
401 UNAUTHORISED
403 NO PERMISSION
404 RESOURCE NOT FOUND
500 INTERNAL ERROR
...
Client
Server
GET
POST
request
response
200 OK
500 INTERNAL ERROR
curl -g \
-X POST \
-H "Content-Type: application/json" \
https://pkff9q.sse.codesandbox.io/
none (default) | null | null | silent |
ignore | ✅ | ✅ | silent |
all | ✅ | ✅ | ✅ |
data (partial) | errors | UI |
Apollo Server
Apollo Client
ErrorLink
RetryLink
Apollo Links
HttpLink
response
request