Skip to content

Commit 35ebfec

Browse files
committedNov 27, 2021
update sdk
1 parent 0c34116 commit 35ebfec

30 files changed

+2189
-2484
lines changed
 

‎.wundergraph/.graphqlconfig

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Follow this guide to configure your Authentication Providers
2+
3+
## Provider: github (GitHub)
4+
5+
### Authorization Callback URL
6+
7+
Make sure to register this URL on your Authentication Provider.
8+
If you don't or misspell the URL, you'll get an invalid callback URL error when trying to log in a user.
9+
Remember that the authentication flow is handled server-side, on the WunderNode.
10+
It's not handled on the server that's hosting the frontend.
11+
12+
```
13+
http://localhost:9991/api/main/auth/cookie/callback/github
14+
15+
## Provider: authzero (OpenID Connect)
16+
17+
### Authorization Callback URL
18+
19+
Make sure to register this URL on your Authentication Provider.
20+
If you don't or misspell the URL, you'll get an invalid callback URL error when trying to log in a user.
21+
Remember that the authentication flow is handled server-side, on the WunderNode.
22+
It's not handled on the server that's hosting the frontend.
23+
24+
```
25+
http://localhost:9991/api/main/auth/cookie/callback/authzero
26+
```

‎.wundergraph/generated/client.ts

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import {
2-
AddMessageInput,
32
AddMessageResponse,
3+
AddMessageInput,
44
AllUsersResponse,
5-
DeleteAllMessagesByUserEmailInput,
5+
AllUsersInput,
6+
ChangeUserNameResponse,
7+
ChangeUserNameInput,
68
DeleteAllMessagesByUserEmailResponse,
9+
DeleteAllMessagesByUserEmailInput,
710
MessagesResponse,
811
MockQueryResponse,
12+
UserInfoResponse,
913
} from "./models";
1014

1115
export const WUNDERGRAPH_S3_ENABLED = false;
@@ -107,6 +111,7 @@ export interface ClientConfig {
107111

108112
export enum AuthProviderId {
109113
"github" = "github",
114+
"authzero" = "authzero",
110115
}
111116

112117
export interface AuthProvider {
@@ -129,9 +134,9 @@ export class Client {
129134
};
130135
private extraHeaders?: HeadersInit;
131136
private readonly baseURL: string = "http://localhost:9991";
132-
private readonly applicationHash: string = "e6b49e3f";
137+
private readonly applicationHash: string = "71b8caa0";
133138
private readonly applicationPath: string = "api/main";
134-
private readonly sdkVersion: string = "0.43.3";
139+
private readonly sdkVersion: string = "0.48.1";
135140
private csrfToken: string | undefined;
136141
private user: User | null;
137142
private userListener: UserListener | undefined;
@@ -151,7 +156,7 @@ export class Client {
151156
}
152157
};
153158
public query = {
154-
AllUsers: async (options: RequestOptions<never, AllUsersResponse>) => {
159+
AllUsers: async (options: RequestOptions<AllUsersInput, AllUsersResponse>) => {
155160
return await this.doFetch<AllUsersResponse>({
156161
method: "GET",
157162
path: "AllUsers",
@@ -175,6 +180,14 @@ export class Client {
175180
abortSignal: options.abortSignal,
176181
});
177182
},
183+
UserInfo: async (options: RequestOptions<never, UserInfoResponse>) => {
184+
return await this.doFetch<UserInfoResponse>({
185+
method: "GET",
186+
path: "UserInfo",
187+
input: options.input,
188+
abortSignal: options.abortSignal,
189+
});
190+
},
178191
};
179192
public mutation = {
180193
AddMessage: async (options: RequestOptions<AddMessageInput, AddMessageResponse>) => {
@@ -185,6 +198,14 @@ export class Client {
185198
abortSignal: options.abortSignal,
186199
});
187200
},
201+
ChangeUserName: async (options: RequestOptions<ChangeUserNameInput, ChangeUserNameResponse>) => {
202+
return await this.doFetch<ChangeUserNameResponse>({
203+
method: "POST",
204+
path: "ChangeUserName",
205+
input: options.input,
206+
abortSignal: options.abortSignal,
207+
});
208+
},
188209
DeleteAllMessagesByUserEmail: async (
189210
options: RequestOptions<DeleteAllMessagesByUserEmailInput, DeleteAllMessagesByUserEmailResponse>
190211
) => {
@@ -198,7 +219,7 @@ export class Client {
198219
};
199220
public liveQuery = {
200221
AllUsers: (
201-
options: RequestOptions<never, AllUsersResponse>,
222+
options: RequestOptions<AllUsersInput, AllUsersResponse>,
202223
cb: (response: Response<AllUsersResponse>) => void
203224
) => {
204225
return this.startSubscription<AllUsersResponse>(
@@ -242,6 +263,21 @@ export class Client {
242263
cb
243264
);
244265
},
266+
UserInfo: (
267+
options: RequestOptions<never, UserInfoResponse>,
268+
cb: (response: Response<UserInfoResponse>) => void
269+
) => {
270+
return this.startSubscription<UserInfoResponse>(
271+
{
272+
method: "GET",
273+
path: "UserInfo",
274+
input: options.input,
275+
abortSignal: options.abortSignal,
276+
liveQuery: true,
277+
},
278+
cb
279+
);
280+
},
245281
};
246282
private doFetch = async <T>(fetchConfig: FetchConfig): Promise<Response<T>> => {
247283
try {
@@ -425,12 +461,19 @@ export class Client {
425461
github: (redirectURI?: string): void => {
426462
this.startLogin(AuthProviderId.github, redirectURI);
427463
},
464+
authzero: (redirectURI?: string): void => {
465+
this.startLogin(AuthProviderId.authzero, redirectURI);
466+
},
428467
};
429468
public authProviders: Array<AuthProvider> = [
430469
{
431470
id: AuthProviderId.github,
432471
login: this.login[AuthProviderId.github],
433472
},
473+
{
474+
id: AuthProviderId.authzero,
475+
login: this.login[AuthProviderId.authzero],
476+
},
434477
];
435478
public logout = async (): Promise<boolean> => {
436479
const response = await fetch(this.baseURL + "/" + this.applicationPath + "/auth/cookie/user/logout", {

‎.wundergraph/generated/forms.tsx

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import { Response } from "./client";
33
import {
44
AddMessageInput,
55
AddMessageResponse,
6+
AllUsersInput,
7+
AllUsersResponse,
8+
ChangeUserNameInput,
9+
ChangeUserNameResponse,
610
DeleteAllMessagesByUserEmailInput,
711
DeleteAllMessagesByUserEmailResponse,
812
} from "./models";
9-
import { useMutation } from "./hooks";
13+
import { useQuery, useLiveQuery, useMutation } from "./hooks";
1014
import jsonSchema from "./jsonschema";
1115
import Form from "@rjsf/core";
1216

@@ -48,6 +52,35 @@ export const AddMessageForm: React.FC<MutationFormProps<Response<AddMessageRespo
4852
</div>
4953
);
5054
};
55+
export const ChangeUserNameForm: React.FC<MutationFormProps<Response<ChangeUserNameResponse>>> = ({
56+
onResult,
57+
refetchMountedQueriesOnSuccess,
58+
liveValidate,
59+
}) => {
60+
const [formData, setFormData] = useState<ChangeUserNameInput>();
61+
const { mutate, response } = useMutation.ChangeUserName({ refetchMountedQueriesOnSuccess });
62+
useEffect(() => {
63+
if (onResult) {
64+
onResult(response);
65+
}
66+
}, [response]);
67+
return (
68+
<div>
69+
<Form
70+
schema={jsonSchema.ChangeUserName.input}
71+
formData={formData}
72+
liveValidate={liveValidate}
73+
onChange={(e) => {
74+
setFormData(e.formData);
75+
}}
76+
onSubmit={async (e) => {
77+
await mutate({ input: e.formData, refetchMountedQueriesOnSuccess });
78+
setFormData(undefined);
79+
}}
80+
/>
81+
</div>
82+
);
83+
};
5184
export const DeleteAllMessagesByUserEmailForm: React.FC<
5285
MutationFormProps<Response<DeleteAllMessagesByUserEmailResponse>>
5386
> = ({ onResult, refetchMountedQueriesOnSuccess, liveValidate }) => {
@@ -75,3 +108,51 @@ export const DeleteAllMessagesByUserEmailForm: React.FC<
75108
</div>
76109
);
77110
};
111+
112+
export const AllUsersForm: React.FC<FormProps<Response<AllUsersResponse>>> = ({ onResult, liveValidate }) => {
113+
const [formData, setFormData] = useState<AllUsersInput>();
114+
const { response, refetch } = useQuery.AllUsers({ input: formData });
115+
useEffect(() => {
116+
if (onResult) {
117+
onResult(response);
118+
}
119+
}, [response]);
120+
return (
121+
<div>
122+
<Form
123+
schema={jsonSchema.AllUsers.input}
124+
formData={formData}
125+
liveValidate={liveValidate}
126+
onChange={(e) => {
127+
setFormData(e.formData);
128+
}}
129+
onSubmit={async (e) => {
130+
await refetch({ input: formData });
131+
}}
132+
/>
133+
</div>
134+
);
135+
};
136+
137+
export const AllUsersLiveForm: React.FC<FormProps<Response<AllUsersResponse>>> = ({ onResult, liveValidate }) => {
138+
const [formData, setFormData] = useState<AllUsersInput>();
139+
const { response } = useLiveQuery.AllUsers({ input: formData });
140+
useEffect(() => {
141+
if (onResult) {
142+
onResult(response);
143+
}
144+
}, [response]);
145+
return (
146+
<div>
147+
<Form
148+
schema={jsonSchema.AllUsers.input}
149+
formData={formData}
150+
liveValidate={liveValidate}
151+
onChange={(e) => {
152+
setFormData(e.formData);
153+
}}
154+
children={<></>}
155+
/>
156+
</div>
157+
);
158+
};

‎.wundergraph/generated/hooks.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import { WunderGraphContext } from "./provider";
33
import { RequestOptions, MutateRequestOptions, SubscriptionRequestOptions, Response } from "./client";
44
import {
55
AddMessageInput,
6+
AllUsersInput,
7+
ChangeUserNameInput,
68
DeleteAllMessagesByUserEmailInput,
79
AllUsersResponse,
810
MessagesResponse,
911
MockQueryResponse,
12+
UserInfoResponse,
1013
} from "./models";
1114

1215
export const useWunderGraph = () => {
@@ -199,7 +202,7 @@ const Subscription = <R, I>(
199202
};
200203

201204
export const useQuery = {
202-
AllUsers: (options?: RequestOptions<never, AllUsersResponse>) => {
205+
AllUsers: (options: RequestOptions<AllUsersInput, AllUsersResponse>) => {
203206
const { client } = useWunderGraph();
204207
return Query(client.query.AllUsers, { requiresAuthentication: false }, options);
205208
},
@@ -211,21 +214,29 @@ export const useQuery = {
211214
const { client } = useWunderGraph();
212215
return Query(client.query.MockQuery, { requiresAuthentication: false }, options);
213216
},
217+
UserInfo: (options?: RequestOptions<never, UserInfoResponse>) => {
218+
const { client } = useWunderGraph();
219+
return Query(client.query.UserInfo, { requiresAuthentication: true }, options);
220+
},
214221
};
215222

216223
export const useMutation = {
217224
AddMessage: (options: MutateRequestOptions<AddMessageInput>) => {
218225
const { client } = useWunderGraph();
219226
return Mutation(client.mutation.AddMessage, { requiresAuthentication: true }, options);
220227
},
228+
ChangeUserName: (options: MutateRequestOptions<ChangeUserNameInput>) => {
229+
const { client } = useWunderGraph();
230+
return Mutation(client.mutation.ChangeUserName, { requiresAuthentication: true }, options);
231+
},
221232
DeleteAllMessagesByUserEmail: (options: MutateRequestOptions<DeleteAllMessagesByUserEmailInput>) => {
222233
const { client } = useWunderGraph();
223234
return Mutation(client.mutation.DeleteAllMessagesByUserEmail, { requiresAuthentication: true }, options);
224235
},
225236
};
226237

227238
export const useLiveQuery = {
228-
AllUsers: (options?: SubscriptionRequestOptions) => {
239+
AllUsers: (options: SubscriptionRequestOptions<AllUsersInput>) => {
229240
const { client } = useWunderGraph();
230241
return Subscription(client.liveQuery.AllUsers, { requiresAuthentication: false }, options);
231242
},
@@ -237,4 +248,8 @@ export const useLiveQuery = {
237248
const { client } = useWunderGraph();
238249
return Subscription(client.liveQuery.MockQuery, { requiresAuthentication: false }, options);
239250
},
251+
UserInfo: (options?: SubscriptionRequestOptions) => {
252+
const { client } = useWunderGraph();
253+
return Subscription(client.liveQuery.UserInfo, { requiresAuthentication: true }, options);
254+
},
240255
};

0 commit comments

Comments
 (0)