Skip to content

Instantly share code, notes, and snippets.

Avatar

Dennis Walsh LawJolla

View GitHub Profile
View .eslintrc
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": false,
"codeFrame": false
},
"env": {
"es6": true,
"browser": true,
View scratch.graphql
mutation {
updateAskingPrice(id: "1", newPrice: 10000) {
id
year
make
model
askingPrice
}
}
View scratch.graphql
type Vehicle {
id: ID!
year: Int!
make: String!
model: Int!
askingPrice: Float @isAuthenticated
costBasis: Float @hasRole(role: “MANAGER”)
numberOfOffers: Int @hasRole(role: “MANAGER”)
}
View scratch.graphql
type Vehicle {
id: ID!
year: Int!
make: String!
model: Int!
askingPrice: Float @isAuthenticated
costBasis: Float @hasRole(role: “MANAGER”)
numberOfOffers: Int @hasRole(role: “MANAGER”)
}
@LawJolla
LawJolla / scratch_33.es6
Created Feb 26, 2018
makeExecutableSchema
View scratch_33.es6
export const schema = makeExecutableSchema({
typeDefs,
resolvers,
directiveResolvers
});
@LawJolla
LawJolla / scratch_33.es6
Created Feb 26, 2018
Clutter free resolver
View scratch_33.es6
const Query = {
vehicles: (parent, args, context, info) =>
context.db.query.vehicles({ where: { dealership: args.id } })
}
@LawJolla
LawJolla / scratch_33.es6
Created Feb 26, 2018
hasRole directive resolver
View scratch_33.es6
const directiveResolvers = {
...,
hasRole: (next, source, {role}, ctx) => {
const user = getUser()
if (role === user.role) return next();
throw new Error(`Must have role: ${role}, you have role: ${user.role}`)
},
...
}
@LawJolla
LawJolla / scratch.graphql
Last active Mar 1, 2018
Directed Schema
View scratch.graphql
directive @isAuthenticated on FIELD | FIELD_DEFINITION
directive @hasRole(role: String) on FIELD | FIELD_DEFINITION
...
type Mutation {
updateAskingPrice(id: ID!, newPrice: Float!): Vehicle! @hasRole(role: "MANAGER")
}
...
View scratch_33.es6
const Query = {
vehicles: async (parent, args, context, info) => {
const vehicles = await context.db.query.vehicles({
where: { dealership: args.id }
})
const user = getUser(context)
return protectFieldsByRole(
[
{ field: `costBasis`, role: `MANAGER` },
{ field: `numberOfOffers`, role: `MANAGER` }
You can’t perform that action at this time.