Skip to content

Instantly share code, notes, and snippets.

View LawJolla's full-sized avatar

Dennis Walsh LawJolla

View GitHub Profile
@LawJolla
LawJolla / gatsby-node.js
Created September 18, 2017 05:15
Gatsby Create pages from API
// Lightweight GraphQL generic client
const GraphQLClient = require('graphql-request').GraphQLClient;
const crypto = require('crypto');
const path = require('path');
const api = require('./api_constants');
//GraphQL query string to get all inventory, filtering by a specific dealer
const vehicles = `
{
allDealerships(filter:{ name:"Wheel Kinetics"}) {
@LawJolla
LawJolla / .eslintrc
Created September 16, 2019 17:11
Global eslint
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": false,
"codeFrame": false
},
"env": {
"es6": true,
"browser": true,
@LawJolla
LawJolla / .eslintrc
Created September 16, 2019 17:10
Global Eslint
extend
@LawJolla
LawJolla / schema.ex
Created April 10, 2017 23:44
Absinthe Root Query Pagination
defmodule WkGraphql.Schema do
use Absinthe.Schema
import_types WkGraphql.Schema.Types
query do
@desc "Get a user"
field :user, :user do
arg :id, non_null(:integer)
resolve &WkGraphql.UserResolver.find/2
@LawJolla
LawJolla / gatsby-node.js
Last active June 25, 2018 18:52
Gatsby + API / GraphQL Call
const GraphQLClient = require('graphql-request').GraphQLClient;
const crypto = require('crypto');
const path = require('path');
module.exports.sourceNodes = async ({ boundActionCreators }) => {
const { createNode } = boundActionCreators
const client = new GraphQLClient(process.env.GRAPHCOOL_API)
const data = await client.request(vehicles)
@LawJolla
LawJolla / scratch_33.es6
Last active March 1, 2018 15:39
Wrapped Query
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` }
@LawJolla
LawJolla / scratch.graphql
Last active March 1, 2018 14:57
Directed Schema
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")
}
...
@LawJolla
LawJolla / scratch.graphql
Last active March 1, 2018 14:52
Updated schema
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.graphql
Last active March 1, 2018 14:49
Directive Permission Schema
type Query {
vehicles(dealership: ID!): [Vehicle!]!
}
type Mutation {
updateVehicleAskingPrice(id: ID!, askingPrice: Int!): Vehicle
}
type Vehicle {
id: ID!
@LawJolla
LawJolla / scratch.graphql
Created February 26, 2018 23:40
example mutation
mutation {
updateAskingPrice(id: "1", newPrice: 10000) {
id
year
make
model
askingPrice
}
}