Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1317 from oxaudo/bnow
add FollowProfile mutation
- Loading branch information
Showing
6 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
}, | ||
}) | ||
}) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 })) | ||
}, | ||
}) |
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
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