Skip to content

Commit

Permalink
Merge pull request #1317 from oxaudo/bnow
Browse files Browse the repository at this point in the history
add FollowProfile mutation
  • Loading branch information
oxaudo committed Oct 2, 2018
2 parents 2010735 + 8d0c291 commit d5afba3
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 1 deletion.
14 changes: 14 additions & 0 deletions _schema.graphql
Expand Up @@ -2982,6 +2982,17 @@ type FollowGenePayload {
clientMutationId: String
}

input FollowProfileInput {
profile_id: String
unfollow: Boolean = false
clientMutationId: String
}

type FollowProfilePayload {
profile: Profile
clientMutationId: String
}

type FollowsAndSaves {
# A list of published artworks by followed artists (grouped by date and artists).
bundledArtworksByArtist(
Expand Down Expand Up @@ -4372,6 +4383,9 @@ type Mutation {
# Follow (or unfollow) an artist
followArtist(input: FollowArtistInput!): FollowArtistPayload

# Follow (or unfollow) a profile
followProfile(input: FollowProfileInput!): FollowProfilePayload

# Follow (or unfollow) an gene
followGene(input: FollowGeneInput!): FollowGenePayload

Expand Down
10 changes: 10 additions & 0 deletions src/lib/loaders/loaders_with_authentication/gravity.ts
Expand Up @@ -174,6 +174,16 @@ export default (accessToken, userID, opts) => {
{},
{ method: "DELETE" }
),
followProfileLoader: gravityLoader(
"me/follow/profile",
{},
{ method: "POST" }
),
unfollowProfileLoader: gravityLoader(
id => `me/follow/profile/${id}`,
{},
{ method: "DELETE" }
),
saveArtworkLoader: gravityLoader(
id => `collection/saved-artwork/artwork/${id}`,
{},
Expand Down
37 changes: 37 additions & 0 deletions src/schema/me/__tests__/follow_profile.test.ts
@@ -0,0 +1,37 @@
/* eslint-disable promise/always-return */
import { runAuthenticatedQuery } from "test/utils"

describe("FollowProfile", () => {
let profile: any
let rootValue: any

beforeEach(() => {
profile = { owner: { name: "Casey Kaplan" }, initials: "CK" }
rootValue = {
profileLoader: () => Promise.resolve(profile),
followProfileLoader: () => Promise.resolve(profile),
unfollowProfileLoader: () => Promise.resolve(profile),
}
})

it("follows a profile", () => {
const mutation = `
mutation {
followProfile(input: { profile_id: "casey-kaplan" }) {
profile {
name
}
}
}
`

expect.assertions(1)
return runAuthenticatedQuery(mutation, rootValue).then(data => {
expect(data!.followProfile).toEqual({
profile: {
name: "Casey Kaplan",
},
})
})
})
})
46 changes: 46 additions & 0 deletions src/schema/me/follow_profile.ts
@@ -0,0 +1,46 @@
import { GraphQLString, GraphQLBoolean } from "graphql"
import { mutationWithClientMutationId } from "graphql-relay"
import { ProfileType } from "schema/profile"

export default mutationWithClientMutationId({
name: "FollowProfile",
description: "Follow (or unfollow) a profile",
inputFields: {
profile_id: {
type: GraphQLString,
},
unfollow: {
type: GraphQLBoolean,
defaultValue: false,
},
},
outputFields: {
profile: {
type: ProfileType,
resolve: (
{ profile_id },
_options,
_request,
{ rootValue: { profileLoader } }
) => profileLoader(profile_id),
},
},
mutateAndGetPayload: (
{ profile_id, unfollow },
_request,
{ rootValue: { accessToken, followProfileLoader, unfollowProfileLoader } }
) => {
if (!accessToken) {
return new Error("You need to be signed in to perform this action")
}

let performAction
if (unfollow) {
performAction = unfollowProfileLoader(profile_id)
} else {
performAction = followProfileLoader({ profile_id })
}

return performAction.then(() => ({ profile_id }))
},
})
2 changes: 1 addition & 1 deletion src/schema/profile.js
Expand Up @@ -10,7 +10,7 @@ import {
GraphQLBoolean,
} from "graphql"

const ProfileType = new GraphQLObjectType({
export const ProfileType = new GraphQLObjectType({
name: "Profile",
fields: () => ({
...GravityIDFields,
Expand Down
2 changes: 2 additions & 0 deletions src/schema/schema.ts
Expand Up @@ -34,6 +34,7 @@ import FilterPartners from "./filter_partners"
import filterArtworks from "./filter_artworks"
import FilterSaleArtworks from "./filter_sale_artworks"
import FollowArtist from "./me/follow_artist"
import FollowProfile from "./me/follow_profile"
import FollowGene from "./me/follow_gene"
import PartnerCategory from "./partner_category"
import PartnerCategories from "./partner_categories"
Expand Down Expand Up @@ -202,6 +203,7 @@ export default new GraphQLSchema({
createCreditCard: createCreditCardMutation,
deleteCreditCard: deleteCreditCardMutation,
followArtist: FollowArtist,
followProfile: FollowProfile,
followGene: FollowGene,
updateCollectorProfile: UpdateCollectorProfile,
updateMyUserProfile: UpdateMyUserProfileMutation,
Expand Down

0 comments on commit d5afba3

Please sign in to comment.