Skip to content

Commit eeb9e76

Browse files
committed
chore: add shared types
1 parent 7eb549a commit eeb9e76

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

types.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { MessageType } from "./constants.ts";
2+
import { ExecutionArgs, GraphQLError, json, PartialBy } from "./deps.ts";
3+
4+
interface BaseMessage {
5+
type: MessageType;
6+
}
7+
8+
type PartialGraphQLParameter = keyof Omit<GraphQLParameters, "query">;
9+
10+
export interface SubscribeMessage extends BaseMessage {
11+
type: MessageType.Subscribe;
12+
payload: Readonly<PartialGraphQLParameters>;
13+
}
14+
15+
export type PartialGraphQLParameters = PartialBy<
16+
GraphQLParameters,
17+
PartialGraphQLParameter
18+
>;
19+
20+
/** GraphQL over HTTP Request parameters.
21+
* @see https://graphql.github.io/graphql-over-http/draft/#sec-Request-Parameters
22+
*/
23+
export type GraphQLParameters = {
24+
/** A Document containing GraphQL Operations and Fragments to execute. */
25+
query: string;
26+
27+
/** Values for any Variables defined by the Operation. */
28+
variableValues: Record<string, json> | null;
29+
30+
/** The name of the Operation in the Document to execute. */
31+
operationName: string | null;
32+
33+
/** Reserved for implementors to extend the protocol however they see fit. */
34+
extensions: Record<string, json> | null;
35+
};
36+
37+
export interface ExecutionResult<
38+
Data = Record<string, unknown>,
39+
Extensions = Record<string, unknown>,
40+
> {
41+
errors?: ReadonlyArray<GraphQLError>;
42+
data?: Data | null;
43+
extensions?: Extensions;
44+
}
45+
46+
export interface NextMessage extends BaseMessage {
47+
type: MessageType.Next;
48+
payload: ExecutionResult;
49+
}
50+
51+
export interface ErrorMessage extends BaseMessage {
52+
type: MessageType.Error;
53+
payload: GraphQLError[];
54+
}
55+
56+
export interface CompleteMessage extends BaseMessage {
57+
type: MessageType.Complete;
58+
}
59+
60+
export type Message =
61+
| SubscribeMessage
62+
| NextMessage
63+
| ErrorMessage
64+
| CompleteMessage;
65+
66+
export type GraphQLExecutionArgs = PartialBy<ExecutionArgs, "document">;

0 commit comments

Comments
 (0)