This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"}) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"parser": "@typescript-eslint/parser", | |
"parserOptions": { | |
"sourceType": "module", | |
"allowImportExportEverywhere": false, | |
"codeFrame": false | |
}, | |
"env": { | |
"es6": true, | |
"browser": true, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Vehicle { | |
id: ID! | |
year: Int! | |
make: String! | |
model: Int! | |
askingPrice: Float @isAuthenticated | |
costBasis: Float @hasRole(role: “MANAGER”) | |
numberOfOffers: Int @hasRole(role: “MANAGER”) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Query { | |
vehicles(dealership: ID!): [Vehicle!]! | |
} | |
type Mutation { | |
updateVehicleAskingPrice(id: ID!, askingPrice: Int!): Vehicle | |
} | |
type Vehicle { | |
id: ID! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mutation { | |
updateAskingPrice(id: "1", newPrice: 10000) { | |
id | |
year | |
make | |
model | |
askingPrice | |
} | |
} |