Skip to content

Commit f0e05d3

Browse files
committed
Fix naming & remove wrapper
1 parent b23c7dc commit f0e05d3

File tree

5 files changed

+35
-34
lines changed

5 files changed

+35
-34
lines changed

graphql/builder.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ export const builder = new SchemaBuilder<PothosTypes>({
153153
relay: {
154154
clientMutationId: "optional",
155155
},
156+
errors: {
157+
directResult: true,
158+
defaultUnionOptions: {
159+
name(options) {
160+
return `${options.fieldName.charAt(0).toUpperCase()}${
161+
options.fieldName.slice(1)
162+
}Result`;
163+
},
164+
},
165+
},
156166
});
157167

158168
builder.addScalarType("Date", DateResolver);

graphql/login.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ builder.mutationFields((t) => ({
6969
type: LoginChallengeRef,
7070
errors: {
7171
types: [AccountNotFoundError],
72+
union: {
73+
name: "LoginResult",
74+
},
7275
result: {
7376
name: "LoginSuccess",
7477
},
@@ -132,6 +135,9 @@ builder.mutationFields((t) => ({
132135
type: LoginChallengeRef,
133136
errors: {
134137
types: [AccountNotFoundError],
138+
union: {
139+
name: "LoginResult",
140+
},
135141
result: {
136142
name: "LoginSuccess",
137143
},

graphql/post.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,6 @@ builder.relayMutationField(
477477
NotAuthenticatedError,
478478
InvalidInputError,
479479
],
480-
result: {
481-
name: "CreateNoteSuccess",
482-
},
483480
},
484481
async resolve(_root, args, ctx) {
485482
const session = await ctx.session;

graphql/schema.graphql

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,7 @@ type CreateNotePayload {
288288
note: Note!
289289
}
290290

291-
type CreateNoteSuccess {
292-
data: CreateNotePayload!
293-
}
291+
union CreateNoteResult = CreateNotePayload | InvalidInputError | NotAuthenticatedError
294292

295293
type CustomEmoji implements Node {
296294
id: ID!
@@ -387,9 +385,7 @@ type LoginChallenge {
387385
token: UUID!
388386
}
389387

390-
type LoginSuccess {
391-
data: LoginChallenge!
392-
}
388+
union LoginResult = AccountNotFoundError | LoginChallenge
393389

394390
"""A Hackers' Pub-flavored Markdown text."""
395391
scalar Markdown
@@ -425,7 +421,7 @@ type Mutation {
425421
"""The signup token."""
426422
token: UUID!
427423
): SignupResult!
428-
createNote(input: CreateNoteInput!): MutationCreateNoteResult!
424+
createNote(input: CreateNoteInput!): CreateNoteResult!
429425
loginByEmail(
430426
"""The email of the account to sign in."""
431427
email: String!
@@ -437,7 +433,7 @@ type Mutation {
437433
The RFC 6570-compliant URI Template for the verification link. Available variabvles: `{token}` and `{code}`.
438434
"""
439435
verifyUrl: URITemplate!
440-
): MutationLoginByUsernameResult!
436+
): LoginResult!
441437
loginByUsername(
442438
"""The locale for the sign-in email."""
443439
locale: Locale!
@@ -449,7 +445,7 @@ type Mutation {
449445
The RFC 6570-compliant URI Template for the verification link. Available variabvles: `{token}` and `{code}`.
450446
"""
451447
verifyUrl: URITemplate!
452-
): MutationLoginByUsernameResult!
448+
): LoginResult!
453449

454450
"""Revoke a session by its ID."""
455451
revokeSession(
@@ -459,10 +455,6 @@ type Mutation {
459455
updateAccount(input: UpdateAccountInput!): UpdateAccountPayload!
460456
}
461457

462-
union MutationCreateNoteResult = CreateNoteSuccess | InvalidInputError | NotAuthenticatedError
463-
464-
union MutationLoginByUsernameResult = AccountNotFoundError | LoginSuccess
465-
466458
interface Node {
467459
id: ID!
468460
}

web-next/src/routes/sign/index.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,14 @@ import type { signCompleteMutation } from "./__generated__/signCompleteMutation.
3232
const signByEmailMutation = graphql`
3333
mutation signByEmailMutation($locale: Locale!, $email: String!, $verifyUrl: URITemplate!) {
3434
loginByEmail(locale: $locale, email: $email, verifyUrl: $verifyUrl) {
35-
... on LoginSuccess {
35+
... on LoginChallenge {
3636
__typename
37-
data {
38-
account {
39-
name
40-
handle
41-
avatarUrl
42-
}
43-
token
37+
account {
38+
name
39+
handle
40+
avatarUrl
4441
}
42+
token
4543
}
4644
... on AccountNotFoundError {
4745
__typename
@@ -53,16 +51,14 @@ const signByEmailMutation = graphql`
5351
const signByUsernameMutation = graphql`
5452
mutation signByUsernameMutation($locale: Locale!, $username: String!, $verifyUrl: URITemplate!) {
5553
loginByUsername(locale: $locale, username: $username, verifyUrl: $verifyUrl) {
56-
... on LoginSuccess {
54+
... on LoginChallenge {
5755
__typename
58-
data {
59-
account {
60-
name
61-
handle
62-
avatarUrl
63-
}
64-
token
56+
account {
57+
name
58+
handle
59+
avatarUrl
6560
}
61+
token
6662
}
6763
... on AccountNotFoundError {
6864
__typename
@@ -171,8 +167,8 @@ export default function SignPage() {
171167

172168
function onCompleted(data: signByUsernameMutation$data["loginByUsername"]) {
173169
setChallenging(false);
174-
if (data.__typename === "LoginSuccess") {
175-
setToken(data.data.token);
170+
if (data.__typename === "LoginChallenge") {
171+
setToken(data.token);
176172
codeInput?.focus();
177173
} else if (
178174
data.__typename === "AccountNotFoundError"

0 commit comments

Comments
 (0)