Chore: Use Fragments as types (#1670)

* Use Fragments as types

Co-authored-by: v1b3m <vibenjamin6@gmail.com>

* Use Fragments as types in GraphQL queries and mutations

Co-authored-by: v1b3m <vibenjamin6@gmail.com>

---------

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
This commit is contained in:
gitstart-twenty
2023-09-20 09:58:59 +01:00
committed by GitHub
parent 3f600146b1
commit 103fb701e7
25 changed files with 354 additions and 561 deletions

View File

@ -0,0 +1,16 @@
import { gql } from '@apollo/client';
export const ACTIVITY_WITH_TARGETS = gql`
fragment ActivityWithTargets on Activity {
id
createdAt
updatedAt
activityTargets {
id
createdAt
updatedAt
companyId
personId
}
}
`;

View File

@ -9,16 +9,7 @@ export const ADD_ACTIVITY_TARGETS = gql`
where: { id: $activityId }
data: { activityTargets: { createMany: { data: $activityTargetInputs } } }
) {
id
createdAt
updatedAt
activityTargets {
id
createdAt
updatedAt
companyId
personId
}
...ActivityWithTargets
}
}
`;

View File

@ -11,16 +11,7 @@ export const REMOVE_ACTIVITY_TARGETS = gql`
activityTargets: { deleteMany: { id: { in: $activityTargetIds } } }
}
) {
id
createdAt
updatedAt
activityTargets {
id
createdAt
updatedAt
companyId
personId
}
...ActivityWithTargets
}
}
`;

View File

@ -0,0 +1,19 @@
import { gql } from '@apollo/client';
export const AUTH_TOKEN = gql`
fragment AuthTokenFragment on AuthToken {
token
expiresAt
}
`;
export const AUTH_TOKENS = gql`
fragment AuthTokensFragment on AuthTokenPair {
accessToken {
...AuthTokenFragment
}
refreshToken {
...AuthTokenFragment
}
}
`;

View File

@ -4,8 +4,7 @@ export const CHALLENGE = gql`
mutation Challenge($email: String!, $password: String!) {
challenge(email: $email, password: $password) {
loginToken {
expiresAt
token
...AuthTokenFragment
}
}
}

View File

@ -8,14 +8,7 @@ export const IMPERSONATE = gql`
...UserQueryFragment
}
tokens {
accessToken {
token
expiresAt
}
refreshToken {
token
expiresAt
}
...AuthTokensFragment
}
}
}

View File

@ -4,14 +4,7 @@ export const RENEW_TOKEN = gql`
mutation RenewToken($refreshToken: String!) {
renewToken(refreshToken: $refreshToken) {
tokens {
accessToken {
expiresAt
token
}
refreshToken {
token
expiresAt
}
...AuthTokensFragment
}
}
}

View File

@ -12,8 +12,7 @@ export const SIGN_UP = gql`
workspaceInviteHash: $workspaceInviteHash
) {
loginToken {
expiresAt
token
...AuthTokenFragment
}
}
}

View File

@ -7,14 +7,7 @@ export const VERIFY = gql`
...UserQueryFragment
}
tokens {
accessToken {
token
expiresAt
}
refreshToken {
token
expiresAt
}
...AuthTokensFragment
}
}
}

View File

@ -1,23 +1,35 @@
import { gql } from '@apollo/client';
export const BASE_COMPANY_FIELDS_FRAGMENT = gql`
fragment baseCompanyFieldsFragment on Company {
address
annualRecurringRevenue
createdAt
domainName
employees
id
idealCustomerProfile
linkedinUrl
name
xUrl
_activityCount
}
`;
export const BASE_ACCOUNT_OWNER_FRAGMENT = gql`
fragment baseAccountOwnerFragment on User {
id
email
displayName
avatarUrl
}
`;
export const COMPANY_FIELDS_FRAGMENT = gql`
fragment companyFieldsFragment on Company {
accountOwner {
id
email
displayName
avatarUrl
...baseAccountOwnerFragment
}
address
createdAt
domainName
employees
linkedinUrl
xUrl
annualRecurringRevenue
idealCustomerProfile
id
name
_activityCount
...baseCompanyFieldsFragment
}
`;

View File

@ -6,25 +6,12 @@ export const GET_COMPANIES = gql`
$where: CompanyWhereInput
) {
companies: findManyCompany(orderBy: $orderBy, where: $where) {
id
domainName
name
createdAt
address
linkedinUrl
xUrl
annualRecurringRevenue
idealCustomerProfile
employees
_activityCount
accountOwner {
id
email
displayName
...baseAccountOwnerFragment
firstName
lastName
avatarUrl
}
...baseCompanyFieldsFragment
}
}
`;

View File

@ -3,23 +3,7 @@ import { gql } from '@apollo/client';
export const GET_COMPANY = gql`
query GetCompany($where: CompanyWhereUniqueInput!) {
findUniqueCompany(where: $where) {
id
domainName
name
createdAt
address
linkedinUrl
xUrl
annualRecurringRevenue
idealCustomerProfile
employees
_activityCount
accountOwner {
id
email
displayName
avatarUrl
}
...companyFieldsFragment
Favorite {
id
person {

View File

@ -1,7 +1,7 @@
import { gql } from '@apollo/client';
export const PERSON_FIELDS_FRAGMENT = gql`
fragment personFieldsFragment on Person {
export const BASE_PERSON_FIELDS_FRAGMENT = gql`
fragment basePersonFieldsFragment on Person {
id
phone
email
@ -9,11 +9,17 @@ export const PERSON_FIELDS_FRAGMENT = gql`
firstName
lastName
displayName
avatarUrl
createdAt
}
`;
export const PERSON_FIELDS_FRAGMENT = gql`
fragment personFieldsFragment on Person {
...basePersonFieldsFragment
jobTitle
linkedinUrl
xUrl
avatarUrl
createdAt
_activityCount
company {
id

View File

@ -6,23 +6,7 @@ export const UPDATE_ONE_PERSON = gql`
$data: PersonUpdateInput!
) {
updateOnePerson(data: $data, where: $where) {
id
city
company {
domainName
name
id
}
avatarUrl
email
jobTitle
linkedinUrl
xUrl
firstName
lastName
displayName
phone
createdAt
...personFieldsFragment
}
}
`;

View File

@ -7,24 +7,7 @@ export const GET_PEOPLE = gql`
$limit: Int
) {
people: findManyPerson(orderBy: $orderBy, where: $where, take: $limit) {
id
phone
email
city
firstName
lastName
displayName
jobTitle
linkedinUrl
xUrl
avatarUrl
createdAt
_activityCount
company {
id
name
domainName
}
...personFieldsFragment
}
}
`;

View File

@ -3,24 +3,7 @@ import { gql } from '@apollo/client';
export const GET_PERSON = gql`
query GetPerson($id: String!) {
findUniquePerson(id: $id) {
id
firstName
lastName
displayName
email
createdAt
city
jobTitle
linkedinUrl
xUrl
avatarUrl
phone
_activityCount
company {
id
name
domainName
}
...personFieldsFragment
Favorite {
id
person {

View File

@ -11,15 +11,7 @@ export const SEARCH_PEOPLE_QUERY = gql`
take: $limit
orderBy: $orderBy
) {
id
phone
email
city
firstName
lastName
displayName
avatarUrl
createdAt
...basePersonFieldsFragment
}
}
`;

View File

@ -11,11 +11,7 @@ export const SEARCH_USER_QUERY = gql`
take: $limit
orderBy: $orderBy
) {
id
email
displayName
firstName
lastName
...userFieldsFragment
avatarUrl
}
}

View File

@ -0,0 +1,11 @@
import { gql } from '@apollo/client';
export const USER_FIELDS_FRAGMENT = gql`
fragment userFieldsFragment on User {
id
email
displayName
firstName
lastName
}
`;

View File

@ -3,50 +3,11 @@ import { gql } from '@apollo/client';
export const GET_CURRENT_USER = gql`
query GetCurrentUser {
currentUser {
id
email
displayName
firstName
lastName
...userFieldsFragment
avatarUrl
canImpersonate
workspaceMember {
id
allowImpersonation
workspace {
id
domainName
displayName
logo
inviteHash
}
assignedActivities {
id
title
}
authoredActivities {
id
title
}
authoredAttachments {
id
name
type
}
settings {
id
colorScheme
locale
}
companies {
id
name
domainName
}
comments {
id
body
}
...workspaceMemberFieldsFragment
}
settings {
id

View File

@ -3,11 +3,7 @@ import { gql } from '@apollo/client';
export const GET_USERS = gql`
query GetUsers {
findManyUser {
id
email
displayName
firstName
lastName
...userFieldsFragment
}
}
`;

View File

@ -0,0 +1,42 @@
import { gql } from '@apollo/client';
export const WORKSPACE_MEMBER_FIELDS_FRAGMENT = gql`
fragment workspaceMemberFieldsFragment on WorkspaceMember {
id
allowImpersonation
workspace {
id
domainName
displayName
logo
inviteHash
}
assignedActivities {
id
title
}
authoredActivities {
id
title
}
authoredAttachments {
id
name
type
}
settings {
id
colorScheme
locale
}
companies {
id
name
domainName
}
comments {
id
body
}
}
`;

View File

@ -6,42 +6,7 @@ export const UPDATE_WORKSPACE_MEMBER = gql`
$where: WorkspaceMemberWhereUniqueInput!
) {
UpdateOneWorkspaceMember(data: $data, where: $where) {
id
allowImpersonation
workspace {
id
domainName
displayName
logo
inviteHash
}
assignedActivities {
id
title
}
authoredActivities {
id
title
}
authoredAttachments {
id
name
type
}
settings {
id
colorScheme
locale
}
companies {
id
name
domainName
}
comments {
id
body
}
...workspaceMemberFieldsFragment
}
}
`;

View File

@ -5,12 +5,8 @@ export const GET_WORKSPACE_MEMBERS = gql`
workspaceMembers: findManyWorkspaceMember(where: $where) {
id
user {
id
email
...userFieldsFragment
avatarUrl
firstName
lastName
displayName
}
}
}