Skip to content

jdivock/chalk-lifts

Repository files navigation

Table of Contents generated with DocToc

Chalk Lifts Build Status

Yeah, writing this (again), using graphQL/Relay, let's see if I can actually get it working.

Setup

Prereqs

  • Postgres (may do sqllite for dev)

Setup

> npm install
> npm start

Relay GraphIQL on http://localhost:8080 App on http://localhost:3000

Schema updates

> npm run update-schema

Relay Queries

Basic

{
  user(email:"jay@jay.com") {
    workouts {
      edges {
        node {
          id,
          name
          lifts {
            edges {
              node {
                id,
                name,
              }
            }
          }
        }
      }
    }
  }
}

Mutations

Remove Lift

mutation RemoveLiftMutation($input: RemoveLiftMutationInput!) {
  removeLift(input: $input) {
    removedLiftId,
    workout {
      id,
      name,
      lifts {
        edges {
          node {
            id,
            name,
          }
        }
      }
    }
  }
}

// Variables
{
  "input": {
    "id": "TGlmdDozMzY",
    "clientMutationId": 0
  }
}

Add Lift

mutation addLift($input: AddLiftMutationInput!) {
  addLiftMutation(input: $input) {
    newLiftEdge {
      node {
        id,
        sets,
        weight,
        reps,
      }
    },
    workout {
      id,
      name,
      lifts {
        edges {
          node {
            id,
            name,
            reps
          }
        }
      }
    }
    clientMutationId
  }
}

// Variables
{
  "input": {
    "workout_id": "V29ya291dDox",
    "sets": 1,
    "reps": 2,
    "weight": 100,
    "name": "stuff",
    "clientMutationId": 0
  }
}

Edit Lift

mutation EditLiftMutation($input: EditLiftMutationInput!) {
  editLift(input: $input) {
    lift {
      name,
      id,
      sets,
    }
  }
}

// Variables
{
  "input": {
      "id": "TGlmdDozMzk=",
      "workout_id": "50",
      "sets": 3,
      "reps": 3,
      "weight": 100,
      "name": "test update",
      "clientMutationId": 0
  }
}

Other Random Relay queries that may or may not work

{
  workout(id:1) {
    id,
    lifts {
      edges {
        cursor,
        node {
          id,
          name,
          sets,
          reps
        }
      },
      pageInfo {
        hasNextPage
        hasPreviousPage
        startCursor
        endCursor
      }
    }
  }
}
Getting 'first' for free with connections
{
  workout(id:1) {
    id,
    lifts(first:1) {
      edges {
        cursor,
        node {
          id,
          name,
          sets,
          reps
        }
      },
      pageInfo {
        hasNextPage
        hasPreviousPage
        startCursor
        endCursor
      }
    }
  }
}
Kitchen Sink
{
  liftToWorkout: lift(id:1) {
    id,
    sets,
    name,
    workout {
      edges {
        cursor,
        node {
          id,
          name,
          date
        }
      }
    }
  }
  workout: workout(id:1) {
    id,
    lifts(first: 2) {
      edges {
        cursor,
        node {
          id,
          name,
          sets,
          reps
        }
      },
      pageInfo {
        hasNextPage
        hasPreviousPage
        startCursor
        endCursor
      }
    }
  },
  account: account(id:1) {
    id,
    email,
    workouts {
      edges {
        cursor,
        node {
          id,
          name,
          date
        }
      }
    }
  }
}
Finding by globalId
query AccountQuery {
  node(id: "QWNjb3VudDox") {
    id
    ... on Account {
      name,
      email
    }
  }
}
Using Cursors
{
  workout: workout(id:1) {
    id,
    name,
    lifts(first: 1) {
      edges {
        cursor,
        node {
          id,
          name
        }
      }
    }
  }
  workoutCont: workout(id:1) {
    id,
    name,
    lifts(first: 5 after: "YXJyYXljb25uZWN0aW9uOjA=") {
      pageInfo {
        hasPreviousPage,
        hasNextPage
      }
      edges {
        cursor,
        node {
          id,
          name
        }
      }
    }
  }
}

DB (knex)

Stil figuring out why, but if I'm tinkering and killing the servr during a seed or migration bad things can happy. in that case

knex migrate:rollback

knex migrate:latest

About

Lift tracking site leveraging GraphQL and Relay

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published