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, getNode, hasNodeChanged }, | |
{ endpoint, token } | |
) => { | |
const { createNode } = boundActionCreators |
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
// 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
import React from 'react' | |
import { renderToString, renderToStaticMarkup } from 'react-dom/server' | |
import ApolloClient, { createNetworkInterface, } from 'apollo-client' | |
import { ApolloProvider, getDataFromTree } from 'react-apollo' | |
// Apollo Setup | |
const networkInterface = createNetworkInterface({ | |
uri: process.env.GRAPHCOOL_API | |
}) |
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
import React from 'react' | |
import { Router } from 'react-router-dom' | |
import ApolloClient, { createNetworkInterface } from 'apollo-client' | |
import { ApolloProvider } from 'react-apollo' | |
import { SubscriptionClient, addGraphQLSubscriptions } from 'subscriptions-transport-ws' | |
const networkInterface = createNetworkInterface({ | |
// endpoint comes from .env.development/production | |
uri: process.env.GRAPHCOOL_API | |
}) |
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
import React from "react"; | |
import { renderToString } from "react-dom/server"; | |
import ApolloClient, { createNetworkInterface } from "apollo-client"; | |
import { ApolloProvider, getDataFromTree } from "react-apollo"; | |
import { ServerStyleSheet, StyleSheetManager } from "styled-components"; | |
// function to generate hydrated state for client side Apollo | |
function makeApolloState(ssrClient) { | |
const state = { apollo: ssrClient.getInitialState() } | |
// appends apollo state to the global client window object |
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
const Mutation = { | |
updateVehicleAskingPrice: async (parent, { id, askingPrice }, context, info) => { | |
const userId = getUserId(context) | |
const isRequestingUserManager = await context.db.exists.User({ | |
id: userId, | |
role: `MANAGER` | |
}) | |
if (isRequestingUserManager) { | |
return await context.db.mutation.updateVehicle({ | |
where: { 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
const Query = { | |
vehicles: async (parent, args, context, info) => { | |
const vehicles = await context.db.query.vehicles({ | |
where: { dealership: args.id } | |
}) | |
const user = getUser(context) | |
return vehicles.map(vehicle => ({ | |
...vehicle, | |
costBasis: |
OlderNewer