@newmo/graphql-codegen-fake-server-client 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -92,7 +92,7 @@ it("register fake response for query", async () => {
92
92
 
93
93
  ### Conditional Fake Responses
94
94
 
95
- You can register conditional fake responses that return different results based on call count or variables. **The variables are now fully type-safe** based on your GraphQL operations:
95
+ You can register conditional fake responses that return different results based on variables. **The variables are now fully type-safe** based on your GraphQL operations:
96
96
 
97
97
  ```ts
98
98
  import { it, expect } from "vitest";
@@ -105,28 +105,6 @@ const fakeClient = createFakeClient({
105
105
  it("register conditional fake responses", async () => {
106
106
  const sequenceId = crypto.randomUUID();
107
107
 
108
- // Return different response on first call
109
- await fakeClient.registerGetBooksQueryResponse(
110
- sequenceId,
111
- {
112
- books: [{ id: "1", title: "First Call" }],
113
- },
114
- {
115
- requestCondition: { type: "count", value: 1 },
116
- }
117
- );
118
-
119
- // Return different response on second call
120
- await fakeClient.registerGetBooksQueryResponse(
121
- sequenceId,
122
- {
123
- books: [{ id: "2", title: "Second Call" }],
124
- },
125
- {
126
- requestCondition: { type: "count", value: 2 },
127
- }
128
- );
129
-
130
108
  // Type-safe variables condition!
131
109
  // TypeScript will enforce the correct variables shape for this operation
132
110
  await fakeClient.registerListDestinationCandidatesQueryResponse(
@@ -8,9 +8,9 @@ const plugin = {
8
8
  const _fakeEndpoint = config.fakeServerEndpoint;
9
9
  const registerOperationResponseType = "{ ok: true } | { ok: false; errors: string[] }"; // Conditional fake types with generic Variables
10
10
  const conditionRuleTypes = `
11
- export type FakeClientCountConditionRule = { type: "count"; value: number };
11
+ export type FakeClientAlwaysConditionRule = { type: "always" };
12
12
  export type FakeClientVariablesConditionRule<TVariables = Record<string, any>> = { type: "variables"; value: TVariables };
13
- export type FakeClientConditionRule<TVariables = Record<string, any>> = FakeClientCountConditionRule | FakeClientVariablesConditionRule<TVariables>;
13
+ export type FakeClientConditionRule<TVariables = Record<string, any>> = FakeClientAlwaysConditionRule | FakeClientVariablesConditionRule<TVariables>;
14
14
  export type FakeClientRegisterSequenceOptions<TVariables = Record<string, any>> = { requestCondition?: FakeClientConditionRule<TVariables> };`;
15
15
  const indentEachLine = (indent, text) => {
16
16
  return text
@@ -58,6 +58,7 @@ ${exportsFunctions
58
58
  const generateRegisterOperationMethod = (name, fakeEndpointVariableName) => {
59
59
  const variablesType = `${(0, convertName_1.convertName)(name, config)}QueryVariables`;
60
60
  return `async register${name}QueryResponse(sequenceId:string, queryResponse: ${name}Query, sequenceOptions?: FakeClientRegisterSequenceOptions<${variablesType}>): Promise<${registerOperationResponseType}> {
61
+ const requestCondition = sequenceOptions?.requestCondition ?? { type: "always" };
61
62
  return await fetch(${fakeEndpointVariableName}, {
62
63
  method: 'POST',
63
64
  headers: {
@@ -68,7 +69,7 @@ ${exportsFunctions
68
69
  type: "operation",
69
70
  operationName: "${name}",
70
71
  data: queryResponse,
71
- ...(sequenceOptions?.requestCondition && { requestCondition: sequenceOptions.requestCondition })
72
+ requestCondition: requestCondition
72
73
  }),
73
74
  }).then((res) => res.json()) as ${registerOperationResponseType};
74
75
  }`;
@@ -93,6 +94,7 @@ ${exportsFunctions
93
94
  const generateRegisterMutationMethod = (name, fakeEndpointVariableName) => {
94
95
  const variablesType = `${(0, convertName_1.convertName)(name, config)}MutationVariables`;
95
96
  return `async register${name}MutationResponse(sequenceId:string, mutationResponse: ${name}Mutation, sequenceOptions?: FakeClientRegisterSequenceOptions<${variablesType}>): Promise<${registerOperationResponseType}> {
97
+ const requestCondition = sequenceOptions?.requestCondition ?? { type: "always" };
96
98
  return await fetch(${fakeEndpointVariableName}, {
97
99
  method: 'POST',
98
100
  headers: {
@@ -103,7 +105,7 @@ ${exportsFunctions
103
105
  type: "operation",
104
106
  operationName: "${name}",
105
107
  data: mutationResponse,
106
- ...(sequenceOptions?.requestCondition && { requestCondition: sequenceOptions.requestCondition })
108
+ requestCondition: requestCondition
107
109
  }),
108
110
  }).then((res) => res.json()) as ${registerOperationResponseType};
109
111
  }`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newmo/graphql-codegen-fake-server-client",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "private": false,
5
5
  "description": "GraphQL Codegen plugin for generating a fake server client",
6
6
  "keywords": [
@@ -61,5 +61,5 @@
61
61
  "access": "public",
62
62
  "registry": "https://registry.npmjs.org/"
63
63
  },
64
- "gitHead": "e7fb0401bb3d6d989adfc98cc15ec4c936bc0cde"
64
+ "gitHead": "251e1b4311a0f070af89abc7e49f6aa1e9b075c0"
65
65
  }
@@ -8,9 +8,9 @@ const plugin: CodegenPlugin<RawPluginConfig> = {
8
8
  const _fakeEndpoint = config.fakeServerEndpoint;
9
9
  const registerOperationResponseType = "{ ok: true } | { ok: false; errors: string[] }"; // Conditional fake types with generic Variables
10
10
  const conditionRuleTypes = `
11
- export type FakeClientCountConditionRule = { type: "count"; value: number };
11
+ export type FakeClientAlwaysConditionRule = { type: "always" };
12
12
  export type FakeClientVariablesConditionRule<TVariables = Record<string, any>> = { type: "variables"; value: TVariables };
13
- export type FakeClientConditionRule<TVariables = Record<string, any>> = FakeClientCountConditionRule | FakeClientVariablesConditionRule<TVariables>;
13
+ export type FakeClientConditionRule<TVariables = Record<string, any>> = FakeClientAlwaysConditionRule | FakeClientVariablesConditionRule<TVariables>;
14
14
  export type FakeClientRegisterSequenceOptions<TVariables = Record<string, any>> = { requestCondition?: FakeClientConditionRule<TVariables> };`;
15
15
  type GenerateFakeFunction =
16
16
  | {
@@ -88,6 +88,7 @@ ${exportsFunctions
88
88
  ) => {
89
89
  const variablesType = `${convertName(name, config)}QueryVariables`;
90
90
  return `async register${name}QueryResponse(sequenceId:string, queryResponse: ${name}Query, sequenceOptions?: FakeClientRegisterSequenceOptions<${variablesType}>): Promise<${registerOperationResponseType}> {
91
+ const requestCondition = sequenceOptions?.requestCondition ?? { type: "always" };
91
92
  return await fetch(${fakeEndpointVariableName}, {
92
93
  method: 'POST',
93
94
  headers: {
@@ -98,7 +99,7 @@ ${exportsFunctions
98
99
  type: "operation",
99
100
  operationName: "${name}",
100
101
  data: queryResponse,
101
- ...(sequenceOptions?.requestCondition && { requestCondition: sequenceOptions.requestCondition })
102
+ requestCondition: requestCondition
102
103
  }),
103
104
  }).then((res) => res.json()) as ${registerOperationResponseType};
104
105
  }`;
@@ -126,6 +127,7 @@ ${exportsFunctions
126
127
  const generateRegisterMutationMethod = (name: string, fakeEndpointVariableName: string) => {
127
128
  const variablesType = `${convertName(name, config)}MutationVariables`;
128
129
  return `async register${name}MutationResponse(sequenceId:string, mutationResponse: ${name}Mutation, sequenceOptions?: FakeClientRegisterSequenceOptions<${variablesType}>): Promise<${registerOperationResponseType}> {
130
+ const requestCondition = sequenceOptions?.requestCondition ?? { type: "always" };
129
131
  return await fetch(${fakeEndpointVariableName}, {
130
132
  method: 'POST',
131
133
  headers: {
@@ -136,7 +138,7 @@ ${exportsFunctions
136
138
  type: "operation",
137
139
  operationName: "${name}",
138
140
  data: mutationResponse,
139
- ...(sequenceOptions?.requestCondition && { requestCondition: sequenceOptions.requestCondition })
141
+ requestCondition: requestCondition
140
142
  }),
141
143
  }).then((res) => res.json()) as ${registerOperationResponseType};
142
144
  }`;