@swcarlosrj
๐คฉ Desktop ~ 100% ย
๐ง Mobile ~ 60%
๐ฑ Watch ~ 20%
๐ /desktop/launches
๐คจ /mobile/launches
๐ค /watch/launches
๐คฉ /launches - 1 HTTP/DB
๐ง /rocket/:id - 'N' HTTP/DB
๐ญ Client parse functions
๐ /graphql - 1 HTTP/'N' DB
๐ No client parse functions
ย
type Query {
launches: [Launch]
launch(id: ID!): Launch
}
type Rocket {
id: ID!
name: String
}
type Launch {
id: ID!
name: String
details: String
image: String
rocket: Rocket
ship: Ship
}
type Ship {
id: ID!
name: String
port: String
image: String
}
Entry points
Type
Sub Types
Query: {
launches: async (obj, args, context) => {
const data = await context.db
.collection('launch')
.toArray();
return data;
},
launch: async (obj, { id }, context) => {
const [data] = await context.db
.collection('launch')
.find({ id })
.toArray();
return data;
},
}
import db from '../db';
import { find, limit, offset, order, sort } from '../utils';
const context = {
db,
find,
limit,
offset,
order,
sort
};
export default context;
const server = new GraphQLServer({
typeDefs,
resolvers,
context
});
server.listen()
Schema First
๐ Fully client-focused design
๐ Code reuse, Type safety
๐ Apollo Server, GraphQL Yoga
Resolver First
๐ Can be type-safe
๐ MVC confusion, less client focus
๐ graphql.js
Model First
๐ Code reuse, Type safety
๐ Most "distance" between code & schema
๐ GraphQL Nexus, TypeGraphQL
type Query {
launches: [Launch]
launch(id: ID!): Launch
}
type Launch {
id: ID!
name: String
details: String
image: String
rocket: Rocket
ship: Ship
}
type Rocket {
id: ID!
name: String
}
type Ship {
id: ID!
name: String
port: String
image: String
}
Query: {
launches: async (obj, args, context) => {
const data = await context.db
.collection('launch')
.toArray();
return data;
},
launch: async (obj, { id }, context) => {
const [data] = await context.db
.collection('launch')
.find({ id })
.toArray();
return data;
},
}
Backend
Frontend
Meetup #2: TypeScript, GraphQL y React
Sevilla TypeScript Meetup