Skip to content

Commit d65d93b

Browse files
committed
update to newest version of sdk
1 parent 29bf4f1 commit d65d93b

19 files changed

+1078
-171
lines changed

.wundergraph/generated/client.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ export interface ClientConfig {
9494
extraHeaders?: HeadersInit;
9595
}
9696

97+
export enum AuthProviderId {
98+
"github" = "github",
99+
}
100+
101+
export interface AuthProvider {
102+
id: AuthProviderId;
103+
login: (redirectURI?: string) => void;
104+
}
105+
97106
export class Client {
98107
constructor(config?: ClientConfig) {
99108
this.baseURL = config?.baseURL || this.baseURL;
@@ -109,9 +118,9 @@ export class Client {
109118
};
110119
private extraHeaders?: HeadersInit;
111120
private readonly baseURL: string = "http://localhost:9991";
112-
private readonly applicationHash: string = "a94200f1";
121+
private readonly applicationHash: string = "18d1f9ce";
113122
private readonly applicationPath: string = "api/main";
114-
private readonly sdkVersion: string = "0.24.1";
123+
private readonly sdkVersion: string = "0.35.0";
115124
private csrfToken: string | undefined;
116125
private user: User | null;
117126
private userListener: UserListener | undefined;
@@ -172,8 +181,8 @@ export class Client {
172181
const params =
173182
fetchConfig.method !== "POST"
174183
? this.queryString({
175-
v: fetchConfig.input,
176-
h: this.applicationHash,
184+
wg_variables: fetchConfig.input,
185+
wg_api_hash: this.applicationHash,
177186
})
178187
: "";
179188
if (fetchConfig.method === "POST" && this.csrfToken === undefined) {
@@ -255,8 +264,8 @@ export class Client {
255264
(async () => {
256265
try {
257266
const params = this.queryString({
258-
v: fetchConfig.input,
259-
live: fetchConfig.liveQuery === true ? true : undefined,
267+
wg_variables: fetchConfig.input,
268+
wg_live: fetchConfig.liveQuery === true ? true : undefined,
260269
});
261270
const response = await fetch(
262271
this.baseURL + "/" + this.applicationPath + "/operations/" + fetchConfig.path + params,
@@ -340,11 +349,17 @@ export class Client {
340349
this.setUser(null);
341350
return null;
342351
};
343-
public login = {
344-
github: (redirectURI?: string) => {
345-
this.startLogin("github", redirectURI);
352+
public login: Record<AuthProviderId, AuthProvider["login"]> = {
353+
github: (redirectURI?: string): void => {
354+
this.startLogin(AuthProviderId.github, redirectURI);
346355
},
347356
};
357+
public authProviders: Array<AuthProvider> = [
358+
{
359+
id: AuthProviderId.github,
360+
login: this.login[AuthProviderId.github],
361+
},
362+
];
348363
public logout = async (): Promise<boolean> => {
349364
const response = await fetch(this.baseURL + "/" + this.applicationPath + "/auth/cookie/user/logout", {
350365
headers: {
@@ -362,7 +377,7 @@ export class Client {
362377
}
363378
return response.status === 200;
364379
};
365-
private startLogin = (providerID: string, redirectURI?: string) => {
380+
private startLogin = (providerID: AuthProviderId, redirectURI?: string) => {
366381
const query = this.queryString({
367382
redirect_uri: redirectURI || window.location.toString(),
368383
});

.wundergraph/generated/forms.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { useEffect, useState } from "react";
2+
import { Response } from "./client";
3+
import { AddMessageInput, AddMessageResponse } from "./models";
4+
import { useMutation } from "./hooks";
5+
import jsonSchema from "./jsonschema";
6+
import Form from "@rjsf/core";
7+
8+
export interface FormProps<T> {
9+
onResult?: (result: T) => void;
10+
liveValidate?: boolean;
11+
}
12+
13+
export interface MutationFormProps<T> extends FormProps<T> {
14+
refetchMountedQueriesOnSuccess?: boolean;
15+
}
16+
17+
export const AddMessageForm: React.FC<MutationFormProps<Response<AddMessageResponse>>> = ({
18+
onResult,
19+
refetchMountedQueriesOnSuccess,
20+
liveValidate,
21+
}) => {
22+
const [formData, setFormData] = useState<AddMessageInput>();
23+
const { mutate, response } = useMutation.AddMessage({ refetchMountedQueriesOnSuccess });
24+
useEffect(() => {
25+
if (onResult) {
26+
onResult(response);
27+
}
28+
}, [response]);
29+
return (
30+
<div>
31+
<Form
32+
schema={jsonSchema.AddMessage.input}
33+
formData={formData}
34+
liveValidate={liveValidate}
35+
onChange={(e) => {
36+
setFormData(e.formData);
37+
}}
38+
onSubmit={async (e) => {
39+
await mutate({ input: e.formData, refetchMountedQueriesOnSuccess });
40+
setFormData(undefined);
41+
}}
42+
/>
43+
</div>
44+
);
45+
};

.wundergraph/generated/hooks.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const Query = <R extends {}, I extends {}>(
5656
if (!initialized) {
5757
return;
5858
}
59-
if (internalOptions.requiresAuthentication && user === undefined) {
59+
if (internalOptions.requiresAuthentication && !user) {
6060
setResponse({ status: "requiresAuthentication" });
6161
return;
6262
}
@@ -111,7 +111,7 @@ const Mutation = <R extends {}, I extends {}>(
111111
const [response, setResponse] = useState<Response<R>>({ status: "none" });
112112
const mutate = useCallback(
113113
async (options?: MutateRequestOptions<I>) => {
114-
if (internalOptions.requiresAuthentication && user === undefined) {
114+
if (internalOptions.requiresAuthentication && !user) {
115115
setResponse({ status: "requiresAuthentication" });
116116
return;
117117
}
@@ -169,7 +169,7 @@ const Subscription = <R, I>(
169169
if (!computedInit) {
170170
return;
171171
}
172-
if (internalOptions.requiresAuthentication && user === undefined) {
172+
if (internalOptions.requiresAuthentication && !user) {
173173
setResponse({ status: "requiresAuthentication" });
174174
return;
175175
}
@@ -195,20 +195,20 @@ const Subscription = <R, I>(
195195
export const useQuery = {
196196
Messages: (options?: RequestOptions<never, MessagesResponse>) => {
197197
const { client } = useWunderGraph();
198-
return Query(client.query.Messages, { requiresAuthentication: true }, options);
198+
return Query(client.query.Messages, { requiresAuthentication: false }, options);
199199
},
200200
};
201201

202202
export const useMutation = {
203203
AddMessage: (options: MutateRequestOptions<AddMessageInput>) => {
204204
const { client } = useWunderGraph();
205-
return Mutation(client.mutation.AddMessage, { requiresAuthentication: true }, options);
205+
return Mutation(client.mutation.AddMessage, { requiresAuthentication: false }, options);
206206
},
207207
};
208208

209209
export const useLiveQuery = {
210210
Messages: (options?: SubscriptionRequestOptions) => {
211211
const { client } = useWunderGraph();
212-
return Subscription(client.liveQuery.Messages, { requiresAuthentication: true }, options);
212+
return Subscription(client.liveQuery.Messages, { requiresAuthentication: false }, options);
213213
},
214214
};

.wundergraph/generated/jsonschema.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { JSONSchema7 } from "json-schema";
2+
3+
interface Schema {
4+
AddMessage: {
5+
input: JSONSchema7;
6+
response: JSONSchema7;
7+
};
8+
Messages: {
9+
input: JSONSchema7;
10+
response: JSONSchema7;
11+
};
12+
}
13+
14+
const jsonSchema: Schema = {
15+
AddMessage: {
16+
input: {
17+
type: "object",
18+
properties: { message: { type: "string" } },
19+
additionalProperties: false,
20+
required: ["message"],
21+
},
22+
response: {
23+
type: "object",
24+
properties: {
25+
data: {
26+
type: "object",
27+
properties: {
28+
createOnemessages: {
29+
type: "object",
30+
properties: { id: { type: "integer" }, message: { type: "string" } },
31+
additionalProperties: false,
32+
required: ["id", "message"],
33+
},
34+
},
35+
additionalProperties: false,
36+
},
37+
},
38+
additionalProperties: false,
39+
},
40+
},
41+
Messages: {
42+
input: { type: "object", properties: {}, additionalProperties: false },
43+
response: {
44+
type: "object",
45+
properties: {
46+
data: {
47+
type: "object",
48+
properties: {
49+
findManymessages: {
50+
type: "array",
51+
items: {
52+
type: "object",
53+
properties: {
54+
id: { type: "integer" },
55+
message: { type: "string" },
56+
users: {
57+
type: "object",
58+
properties: { id: { type: "integer" }, name: { type: "string" } },
59+
additionalProperties: false,
60+
required: ["id", "name"],
61+
},
62+
},
63+
additionalProperties: false,
64+
required: ["id", "message", "users"],
65+
},
66+
},
67+
},
68+
additionalProperties: false,
69+
required: ["findManymessages"],
70+
},
71+
},
72+
additionalProperties: false,
73+
},
74+
},
75+
};
76+
export default jsonSchema;

.wundergraph/generated/provider.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Client, User } from "./client";
1+
import { Client, User, UserListener } from "./client";
22
import React, { createContext, FunctionComponent, useMemo, useEffect, useState, Dispatch, SetStateAction } from "react";
33

44
export interface Config {
@@ -30,16 +30,25 @@ export const WunderGraphProvider: FunctionComponent<Props> = ({ endpoint, childr
3030
const [initializing, setInitializing] = useState(false);
3131
const queryCache: { [key: string]: Object } = {};
3232
const client = useMemo<Client>(() => {
33-
const client = new Client(endpoint);
33+
const client = new Client({ baseURL: endpoint });
3434
client.setLogoutCallback(() => {
3535
Object.keys(queryCache).forEach((key) => {
3636
delete queryCache[key];
3737
});
3838
});
3939
return client;
4040
}, [endpoint]);
41+
const userListener = useMemo<UserListener>(() => {
42+
return (userOrNull) => {
43+
if (userOrNull === null) {
44+
setUser(undefined);
45+
} else {
46+
setUser(userOrNull);
47+
}
48+
};
49+
}, []);
4150
useEffect(() => {
42-
client.setUserListener(setUser);
51+
client.setUserListener(userListener);
4352
(async () => {
4453
await client.fetchUser();
4554
setInitialized(true);

0 commit comments

Comments
 (0)