Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write mutations to: create a community and join a community #41

Merged
merged 24 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fab0fa7
build(deps): update version of koa-graphql dependency
noghartt Dec 15, 2021
796eddd
feat: add headerEditorEnabled on graphiql option on koa-graphql
noghartt Dec 15, 2021
7c52e92
feat: write a auth function to get user if exists
noghartt Dec 15, 2021
d49a8d6
feat: add user to context on graphql request
noghartt Dec 15, 2021
b4c70bd
feat: add communities array as field on the user document
noghartt Dec 15, 2021
9aae6dd
feat: write CommunityModel
noghartt Dec 15, 2021
cbe405b
feat: write CommunityType
noghartt Dec 15, 2021
1ab48e2
feat: write createCommunityMutation
noghartt Dec 15, 2021
26e0ffd
feat: write joinCommunityMutation
noghartt Dec 15, 2021
fce6b07
test: write a method to upsert models on tests
noghartt Dec 15, 2021
b2ecbaf
style: improve types on createUser fixture function
noghartt Dec 15, 2021
38fb0fb
test: write a fixture to create communities
noghartt Dec 15, 2021
7dd3290
test: write tests to createCommunityMutation
noghartt Dec 15, 2021
8a2fe45
test: write tests to joinCommunity.test.ts
noghartt Dec 15, 2021
ccb831f
build(tsconfig): exclude test files and fixtures when build server
noghartt Dec 15, 2021
9c530da
chore(gitignore): fix /graphql folder on gitignore
noghartt Dec 15, 2021
033f29a
style: add setting to detect react version on eslint config
noghartt Dec 15, 2021
7fe1e33
feat: write graphql modules with initial GraphQLContext type
noghartt Dec 15, 2021
97f6002
style: rename community mutations to avoid redundancy
noghartt Dec 15, 2021
671a6bf
fix(community): instantiates a new model with correctly properties
noghartt Dec 15, 2021
0468961
style: move outputFields on community mutations down from resolvers
noghartt Dec 15, 2021
49c02f5
style: change findedCommunity to communityFound
noghartt Dec 15, 2021
6370492
test: rename community mutation tests to according with mutations
noghartt Dec 15, 2021
c746bcf
feat: add ref prop to fields on Community schema
noghartt Dec 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ it('should create a new community', async () => {

const mutation = `
mutation M($displayName: String!, $communityId: String!) {
createCommunityMutation(
communityCreate(
input: { displayName: $displayName, communityId: $communityId }
) {
community {
Expand Down Expand Up @@ -48,7 +48,7 @@ it('should create a new community', async () => {

expect(result.errors).toBeUndefined();

const { community } = result?.data?.createCommunityMutation;
const { community } = result?.data?.communityCreate;

expect(community.id).toBeDefined();
expect(community.name).toBe(variables.communityId);
Expand All @@ -60,7 +60,7 @@ it('should create a new community', async () => {
it("should not allow create a community if doesn't have authorization header", async () => {
const mutation = `
mutation M($displayName: String!, $communityId: String!) {
createCommunityMutation(
communityCreate(
input: { displayName: $displayName, communityId: $communityId }
) {
community {
Expand All @@ -82,7 +82,7 @@ it("should not allow create a community if doesn't have authorization header", a

const result = await graphql(schema, mutation, rootValue, {}, variables);

expect(result?.data?.createCommunityMutation).toBeNull();
expect(result?.data?.communityCreate).toBeNull();

expect(result?.errors).toBeDefined();
expect(result.errors && result.errors[0]?.message).toBe(
Expand All @@ -95,7 +95,7 @@ it('should not create a duplicate community', async () => {

const mutation = `
mutation M($displayName: String!, $communityId: String!) {
createCommunityMutation(
communityCreate(
input: { displayName: $displayName, communityId: $communityId }
) {
community {
Expand Down Expand Up @@ -124,7 +124,7 @@ it('should not create a duplicate community', async () => {
variables,
);

expect(result?.data?.createCommunityMutation).toBeNull();
expect(result?.data?.communityCreate).toBeNull();

expect(result?.errors).toBeDefined();
expect(result.errors && result.errors[0].message).toBe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ it('should join a created community', async () => {
const user = await createUser();

const mutation = `
mutation M($communityId: String!) {
joinCommunityMutation(input: { communityId: $communityId }) {
community {
id
members
}
me {
id
communities
}
}
mutation M($communityId: String!) {
joinCommunity(input: { communityId: $communityId }) {
community {
id
members
}
me {
id
communities
}
}
}
`;

const rootValue = {};
Expand All @@ -51,7 +51,7 @@ it('should join a created community', async () => {

expect(result.errors).toBeUndefined();

const { community, me } = result?.data?.joinCommunityMutation;
const { community, me } = result?.data?.joinCommunity;

expect(me.communities).toHaveLength(1);
expect(me.communities).toContain(fromGlobalId(community.id).id);
Expand All @@ -63,7 +63,7 @@ it('should join a created community', async () => {
it("should not allow to join a community if doesn't have authorization header", async () => {
const mutation = `
mutation M($communityId: String!) {
joinCommunityMutation(input: { communityId: $communityId }) {
joinCommunity(input: { communityId: $communityId }) {
me {
id
}
Expand All @@ -79,7 +79,7 @@ it("should not allow to join a community if doesn't have authorization header",

const result = await graphql(schema, mutation, rootValue, {}, variables);

expect(result?.data?.joinCommunityMutation).toBeNull();
expect(result?.data?.joinCommunity).toBeNull();

expect(result?.errors).toBeDefined();
expect(result.errors && result.errors[0].message).toBe(
Expand All @@ -92,7 +92,7 @@ it('should not join a non-existent community', async () => {

const mutation = `
mutation M($communityId: String!) {
joinCommunityMutation(input: { communityId: $communityId }) {
joinCommunity(input: { communityId: $communityId }) {
me {
id
}
Expand All @@ -115,7 +115,7 @@ it('should not join a non-existent community', async () => {
variables,
);

expect(result?.data?.joinCommunityMutation).toBeNull();
expect(result?.data?.joinCommunity).toBeNull();

expect(result?.errors).toBeDefined();
expect(result.errors && result.errors[0].message).toBe(
Expand All @@ -129,7 +129,7 @@ it('should not join a community that you already is a member', async () => {

const mutation = `
mutation M($communityId: String!) {
joinCommunityMutation(input: { communityId: $communityId }) {
joinCommunity(input: { communityId: $communityId }) {
me {
id
}
Expand All @@ -152,7 +152,7 @@ it('should not join a community that you already is a member', async () => {
variables,
);

expect(result?.data?.joinCommunityMutation).toBeNull();
expect(result?.data?.joinCommunity).toBeNull();

expect(result?.errors).toBeDefined();
expect(result.errors && result.errors[0].message).toBe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { GraphQLContext } from '../../graphql/types';
import { CommunityModel } from '../CommunityModel';
import { CommunityType } from '../CommunityType';

export const createCommunityMutation = mutationWithClientMutationId({
name: 'CreateCommunity',
export const communityCreate = mutationWithClientMutationId({
name: 'CommunityCreate',
inputFields: {
communityId: { type: new GraphQLNonNull(GraphQLString) },
displayName: { type: new GraphQLNonNull(GraphQLString) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { UserModel } from '../../user/UserModel';
import { CommunityModel } from '../CommunityModel';
import { CommunityType } from '../CommunityType';

export const joinCommunityMutation = mutationWithClientMutationId({
name: 'JoinCommunity',
export const communityJoin = mutationWithClientMutationId({
name: 'CommunityJoin',
inputFields: {
communityId: { type: new GraphQLNonNull(GraphQLString) },
},
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/modules/community/mutations/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './createCommunityMutation';
export * from './joinCommunityMutation';
export * from './communityCreateMutation';
noghartt marked this conversation as resolved.
Show resolved Hide resolved
export * from './communityJoinMutation';