-
Notifications
You must be signed in to change notification settings - Fork 89
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
WIP => [Do Not Merge]: Add new createConversation mutation #6401
Open
damassi
wants to merge
2
commits into
main
Choose a base branch
from
damassi/feat/add-create-convo-mutation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+268
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
206 changes: 206 additions & 0 deletions
206
src/schema/v2/conversation/createConversationMutation.ts
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,206 @@ | ||
import { | ||
GraphQLObjectType, | ||
GraphQLUnionType, | ||
GraphQLNonNull, | ||
GraphQLString, | ||
GraphQLEnumType, | ||
GraphQLList, | ||
GraphQLInputObjectType, | ||
} from "graphql" | ||
import { mutationWithClientMutationId } from "graphql-relay" | ||
import { ResolverContext } from "types/graphql" | ||
import { | ||
GravityMutationErrorType, | ||
formatGravityError, | ||
} from "lib/gravityErrorHandler" | ||
import Conversation from "schema/v2/conversation" | ||
|
||
type UserType = "Partner" | "User" | ||
|
||
interface CreateConversationMutationInputProps { | ||
fromId: string | ||
fromType: UserType | ||
fromName: string | ||
fromEmail: string | ||
toId: string | ||
toType: UserType | ||
toName: string | ||
items: Array<{ | ||
itemId: string | ||
itemType: string | ||
}> | ||
} | ||
|
||
const SuccessType = new GraphQLObjectType<any, ResolverContext>({ | ||
name: "CreateConversationSuccess", | ||
isTypeOf: (data) => data.id, | ||
fields: () => ({ | ||
conversation: { | ||
type: Conversation.type, | ||
resolve: (conversation) => conversation, | ||
}, | ||
}), | ||
}) | ||
|
||
const ErrorType = new GraphQLObjectType<any, ResolverContext>({ | ||
name: "CreateConversationFailure", | ||
isTypeOf: (data) => data._type === "GravityMutationError", | ||
fields: () => ({ | ||
mutationError: { | ||
type: GravityMutationErrorType, | ||
resolve: (err) => err, | ||
}, | ||
}), | ||
}) | ||
|
||
const ResponseOrErrorType = new GraphQLUnionType({ | ||
name: "CreateConversationResponseOrError", | ||
types: [SuccessType, ErrorType], | ||
}) | ||
|
||
const CreateConversationTypeEnum = new GraphQLEnumType({ | ||
name: "CreateConversationTypeEnum", | ||
values: { | ||
PARTNER: { | ||
value: "Partner", | ||
}, | ||
USER: { | ||
value: "User", | ||
}, | ||
}, | ||
}) | ||
|
||
const CreateConversationItemTypeEnum = new GraphQLEnumType({ | ||
name: "CreateConversationItemTypeEnum", | ||
values: { | ||
ARTWORK: { | ||
value: "Artwork", | ||
}, | ||
}, | ||
}) | ||
|
||
export const createConversationMutation = mutationWithClientMutationId< | ||
CreateConversationMutationInputProps, | ||
any, | ||
ResolverContext | ||
>({ | ||
name: "CreateConversationMutation", | ||
description: "Create a conversation.", | ||
inputFields: { | ||
fromId: { | ||
type: new GraphQLNonNull(GraphQLString), | ||
description: "The id of the user who sent the message.", | ||
}, | ||
fromType: { | ||
type: new GraphQLNonNull(CreateConversationTypeEnum), | ||
description: "The type of the user who sent the message.", | ||
}, | ||
fromName: { | ||
type: new GraphQLNonNull(GraphQLString), | ||
description: "The name of the user who sent the message.", | ||
}, | ||
fromEmail: { | ||
type: new GraphQLNonNull(GraphQLString), | ||
description: "The email of the user who sent the message.", | ||
}, | ||
toId: { | ||
type: new GraphQLNonNull(GraphQLString), | ||
description: "The id of the user who received the message.", | ||
}, | ||
toType: { | ||
type: new GraphQLNonNull(CreateConversationTypeEnum), | ||
description: "The type of the user who received the message.", | ||
}, | ||
toName: { | ||
type: new GraphQLNonNull(GraphQLString), | ||
description: "The name of the user who received the message.", | ||
}, | ||
exchangeOrderId: { | ||
type: GraphQLString, | ||
description: "The id of the exchange order.", | ||
}, | ||
initialMessage: { | ||
type: GraphQLString, | ||
description: "The initial message in the conversation.", | ||
}, | ||
items: { | ||
description: "The items in the conversation.", | ||
type: new GraphQLNonNull( | ||
new GraphQLList( | ||
new GraphQLInputObjectType({ | ||
name: "CreateConversationItem", | ||
fields: { | ||
itemId: { | ||
type: new GraphQLNonNull(GraphQLString), | ||
description: "The id of the item.", | ||
}, | ||
itemType: { | ||
type: new GraphQLNonNull(CreateConversationItemTypeEnum), | ||
description: "The type of the item.", | ||
}, | ||
}, | ||
}) | ||
) | ||
), | ||
}, | ||
}, | ||
outputFields: { | ||
responseOrError: { | ||
type: ResponseOrErrorType, | ||
resolve: (result) => result, | ||
}, | ||
}, | ||
mutateAndGetPayload: async ( | ||
args, | ||
{ conversationCreateLoader, conversationCreateConversationOrderLoader } | ||
) => { | ||
if ( | ||
!conversationCreateLoader || | ||
!conversationCreateConversationOrderLoader | ||
) { | ||
throw new Error("You need to be signed in to perform this action.") | ||
} | ||
|
||
try { | ||
const conversation = await conversationCreateLoader({ | ||
from_id: args.fromId, | ||
from_type: args.fromType, | ||
from_name: args.fromName, | ||
from_email: args.fromEmail, | ||
intercepted: false, | ||
to_id: args.toId, | ||
to_type: args.toType, | ||
to_name: args.toName, | ||
exchange_order_id: args.exchangeOrderId, | ||
initial_message: args.initialMessage, | ||
items: args.items.map((item) => { | ||
return { | ||
item_id: item.itemId, | ||
item_type: item.itemType, | ||
} | ||
}), | ||
}) | ||
|
||
if (args.exchangeOrderId) { | ||
const conversationOrder = await conversationCreateConversationOrderLoader( | ||
{ | ||
conversation_id: conversation.id, | ||
exchange_order_id: args.exchangeOrderId, | ||
} | ||
) | ||
|
||
return conversationOrder | ||
} | ||
|
||
return conversation | ||
} catch (error) { | ||
const formattedErr = formatGravityError(error) | ||
|
||
if (formattedErr) { | ||
return { ...formattedErr, _type: "GravityMutationError" } | ||
} else { | ||
throw new Error(error) | ||
} | ||
} | ||
}, | ||
}) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised we didn't have this already - we have a bunch of conversation-related mutations in MP already. Are all conversations currently only created via inquiry creation workflow? I see
ConversationService#create_conversation
code in Gravity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, we never exposed anything!