PhotoShare API

PhotoShare is the main back-end exercise for GraphQL Workshop. In this exercise, students build a GraphQL API for a small photo sharing application.

Changes

Add a file type to the Post Photo Input

scalar DateTime

type Photo {
    id: ID!
    name: String!
    url: String!
    description: String
    category: PhotoCategory!
    postedBy: User!
    created: DateTime!
}

Modify the Resolver to Accept the file

resolvers.js

const { GraphQLScalarType } = require('graphql')

__resolvers.js__
...
module.exports = {
    
    ...
    
    DateTime: new GraphQLScalarType({
        name: 'DateTime',
        description: 'A valid date time value.',
        parseValue: value => new Date(value),
        serialize: value => new Date(value).toISOString(),
        parseLiteral: ast => ast.value
    })

}

Test the Upload (no playground)

query {
  allPhotos {
    id
    url
    created
  }
}

Iterations

a. Start

  1. Initial Project Folder
  2. Apollo Server 2.0

b. The Photo Type

  1. Counting the Photos
  2. Posting a Photo
  3. Handling Photo Categories
  4. Using an Input Type
  5. Listing All Photos
  6. Querying a Single Photo

c. The User Type

  1. Challenge: Adding the User Type
  2. Connecting Photos to Users
  3. Connecting Users to Photos
  4. Adding currentUser to context

d. Context

  1. Add environment and refactor
  2. Configuring a Database
  3. Configure an express server
  4. Configure Github OAuth
  5. Add githubLogin mutation
  6. Add fake users to githubLogin mutation
  7. Identify the currentUser
  8. Post new Photos to the Database

e. Subscriptions and Custom Scalars

  1. Adding Subscription Support
  2. Uploading File with postPhoto
  3. Adding custom scalar for DateTime