Skip to content

Commit 304cc18

Browse files
authored
chore: update dependencies of graphql-api (#1135)
1 parent d3662f1 commit 304cc18

File tree

6 files changed

+1152
-172
lines changed

6 files changed

+1152
-172
lines changed

.changeset/itchy-forks-deliver.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@accounts/graphql-api': patch
3+
---
4+
5+
Upgrade dependencies

packages/graphql-api/codegen.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ generates:
1212
noNamespaces: true
1313
noSchemaStitching: true
1414
plugins:
15-
- add: /* eslint-disable */
15+
- add:
16+
content: '/* eslint-disable */'
1617
- typescript
1718
- typescript-resolvers
1819
- typescript-operations

packages/graphql-api/package.json

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,28 @@
4141
"graphql-tag": "^2.10.0"
4242
},
4343
"dependencies": {
44-
"@graphql-tools/merge": "6.2.5",
45-
"@graphql-tools/utils": "7.0.2",
44+
"@graphql-tools/merge": "6.2.13",
45+
"@graphql-tools/utils": "7.9.0",
4646
"request-ip": "2.1.3",
4747
"tslib": "2.1.0"
4848
},
4949
"devDependencies": {
5050
"@accounts/password": "^0.32.0",
5151
"@accounts/server": "^0.32.0",
5252
"@accounts/types": "^0.32.0",
53-
"@graphql-codegen/add": "1.17.4",
54-
"@graphql-codegen/cli": "1.17.4",
55-
"@graphql-codegen/introspection": "1.17.4",
56-
"@graphql-codegen/typescript": "1.17.4",
57-
"@graphql-codegen/typescript-operations": "1.17.4",
58-
"@graphql-codegen/typescript-resolvers": "1.17.4",
59-
"@graphql-codegen/typescript-type-graphql": "1.17.4",
53+
"@graphql-codegen/add": "2.0.2",
54+
"@graphql-codegen/cli": "1.21.4",
55+
"@graphql-codegen/introspection": "1.18.2",
56+
"@graphql-codegen/typescript": "1.22.0",
57+
"@graphql-codegen/typescript-operations": "1.17.16",
58+
"@graphql-codegen/typescript-resolvers": "1.19.1",
59+
"@graphql-codegen/typescript-type-graphql": "1.18.4",
6060
"@graphql-modules/core": "0.7.17",
61-
"@types/jest": "25.2.3",
61+
"@types/jest": "26.0.23",
6262
"@types/request-ip": "0.0.35",
63-
"concurrently": "5.2.0",
6463
"graphql": "14.6.0",
6564
"jest": "26.6.3",
66-
"ts-jest": "26.4.4",
67-
"ts-node": "8.10.1"
65+
"ts-jest": "26.5.6",
66+
"ts-node": "9.1.1"
6867
}
6968
}

packages/graphql-api/src/models.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable */
22
import { GraphQLResolveInfo } from 'graphql';
33
export type Maybe<T> = T | null;
4-
export type Exact<T extends { [key: string]: any }> = { [K in keyof T]: T[K] };
4+
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
5+
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
6+
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
57
export type RequireFields<T, K extends keyof T> = { [X in Exclude<keyof T, K>]?: T[X] } & { [P in K]-?: NonNullable<T[P]> };
6-
78
/** All built-in and custom scalars, mapped to their actual values */
89
export type Scalars = {
910
ID: string;
@@ -250,7 +251,7 @@ export type TypeResolveFn<TTypes, TParent = {}, TContext = {}> = (
250251
info: GraphQLResolveInfo
251252
) => Maybe<TTypes> | Promise<Maybe<TTypes>>;
252253

253-
export type IsTypeOfResolverFn<T = {}> = (obj: T, info: GraphQLResolveInfo) => boolean | Promise<boolean>;
254+
export type IsTypeOfResolverFn<T = {}, TContext = {}> = (obj: T, context: TContext, info: GraphQLResolveInfo) => boolean | Promise<boolean>;
254255

255256
export type NextResolverFn<T> = () => Promise<T>;
256257

@@ -311,27 +312,27 @@ export type AuthDirectiveResolver<Result, Parent, ContextType = any, Args = Auth
311312
export type CreateUserResultResolvers<ContextType = any, ParentType extends ResolversParentTypes['CreateUserResult'] = ResolversParentTypes['CreateUserResult']> = {
312313
userId?: Resolver<Maybe<ResolversTypes['ID']>, ParentType, ContextType>;
313314
loginResult?: Resolver<Maybe<ResolversTypes['LoginResult']>, ParentType, ContextType>;
314-
__isTypeOf?: IsTypeOfResolverFn<ParentType>;
315+
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
315316
};
316317

317318
export type EmailRecordResolvers<ContextType = any, ParentType extends ResolversParentTypes['EmailRecord'] = ResolversParentTypes['EmailRecord']> = {
318319
address?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
319320
verified?: Resolver<Maybe<ResolversTypes['Boolean']>, ParentType, ContextType>;
320-
__isTypeOf?: IsTypeOfResolverFn<ParentType>;
321+
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
321322
};
322323

323324
export type ImpersonateReturnResolvers<ContextType = any, ParentType extends ResolversParentTypes['ImpersonateReturn'] = ResolversParentTypes['ImpersonateReturn']> = {
324325
authorized?: Resolver<Maybe<ResolversTypes['Boolean']>, ParentType, ContextType>;
325326
tokens?: Resolver<Maybe<ResolversTypes['Tokens']>, ParentType, ContextType>;
326327
user?: Resolver<Maybe<ResolversTypes['User']>, ParentType, ContextType>;
327-
__isTypeOf?: IsTypeOfResolverFn<ParentType>;
328+
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
328329
};
329330

330331
export type LoginResultResolvers<ContextType = any, ParentType extends ResolversParentTypes['LoginResult'] = ResolversParentTypes['LoginResult']> = {
331332
sessionId?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
332333
tokens?: Resolver<Maybe<ResolversTypes['Tokens']>, ParentType, ContextType>;
333334
user?: Resolver<Maybe<ResolversTypes['User']>, ParentType, ContextType>;
334-
__isTypeOf?: IsTypeOfResolverFn<ParentType>;
335+
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
335336
};
336337

337338
export type MutationResolvers<ContextType = any, ParentType extends ResolversParentTypes['Mutation'] = ResolversParentTypes['Mutation']> = {
@@ -359,7 +360,7 @@ export type QueryResolvers<ContextType = any, ParentType extends ResolversParent
359360
export type TokensResolvers<ContextType = any, ParentType extends ResolversParentTypes['Tokens'] = ResolversParentTypes['Tokens']> = {
360361
refreshToken?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
361362
accessToken?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
362-
__isTypeOf?: IsTypeOfResolverFn<ParentType>;
363+
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
363364
};
364365

365366
export type TwoFactorSecretKeyResolvers<ContextType = any, ParentType extends ResolversParentTypes['TwoFactorSecretKey'] = ResolversParentTypes['TwoFactorSecretKey']> = {
@@ -371,14 +372,14 @@ export type TwoFactorSecretKeyResolvers<ContextType = any, ParentType extends Re
371372
qr_code_base32?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
372373
google_auth_qr?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
373374
otpauth_url?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
374-
__isTypeOf?: IsTypeOfResolverFn<ParentType>;
375+
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
375376
};
376377

377378
export type UserResolvers<ContextType = any, ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User']> = {
378379
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
379380
emails?: Resolver<Maybe<Array<ResolversTypes['EmailRecord']>>, ParentType, ContextType>;
380381
username?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
381-
__isTypeOf?: IsTypeOfResolverFn<ParentType>;
382+
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
382383
};
383384

384385
export type Resolvers<ContextType = any> = {
@@ -408,4 +409,4 @@ export type DirectiveResolvers<ContextType = any> = {
408409
* @deprecated
409410
* Use "DirectiveResolvers" root object instead. If you wish to get "IDirectiveResolvers", add "typesPrefix: I" to your config.
410411
*/
411-
export type IDirectiveResolvers<ContextType = any> = DirectiveResolvers<ContextType>;
412+
export type IDirectiveResolvers<ContextType = any> = DirectiveResolvers<ContextType>;

website/docs/strategies/oauth.md

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ npm install @accounts/oauth --save
2424
This example is written in Typescript - remove any type definitons if you are using plain JS.
2525

2626
```javascript
27-
import { AccountsServer } from '@accounts/server'
28-
import { AccountsOauth } from '@accounts/oauth'
27+
import { AccountsServer } from '@accounts/server';
28+
import { AccountsOauth } from '@accounts/oauth';
2929

3030
// We create a new OAuth instance (with at least one provider)
3131
const accountsOauth = new AccountsOauth({
3232
// ... OAuth providers
33-
})
33+
});
3434

3535
// We pass the OAuth instance the AccountsServer service list
3636
const accountsServer = new AccountsServer(...config, {
@@ -52,8 +52,7 @@ For Nextcloud, read [their docs](https://docs.nextcloud.com/server/19/admin_manu
5252

5353
In the appropriate place of your app, place an "Authenticate via Nextcloud" button that will open a popup window for the user to authenticate via the OAuth provider.
5454

55-
When receiving this code, the client will send it to the AccountsJS-based server, which will verify it with the provider (Nextcloud) itself (we will define the serverside part later).
56-
55+
When receiving this code, the client will send it to the AccountsJS-based server, which will verify it with the provider (Nextcloud) itself (we will define the serverside part later).
5756

5857
```typescript
5958
import qs from 'qs' // https://www.npmjs.com/package/qs
@@ -81,7 +80,7 @@ function startNextcloudLogin () {
8180
const code = e.data as string
8281
try {
8382
// Send this code to the AccountsJS-based server
84-
await accountsClient.loginWithService('oauth', { provider: 'nextcloud', code })
83+
await accountsClient.loginWithService('oauth', { provider: 'nextcloud', code })
8584
// the 'provider' is key you specify in AccountsOauth config
8685
console.log('User in LoginDialog success', user)
8786
user.value = await accountsClient.getUser()
@@ -114,61 +113,63 @@ The OAuth provider will redirect to the specified `redirectUri` with a query str
114113
The handler `oauthLoginChannel.onmessage` will use that code to authenticate against your app's accountsjs-based server.
115114

116115
Register a route with your router. Example with vue-router:
116+
117117
```typescript
118118
{ path: '/oauth-callback/:service', component: () => import('components/auth/OAuthCallback.vue') }
119119
```
120120

121121
Define the handler (example based on vue-router):
122122

123123
```typescript
124-
import qs from 'qs'
124+
import qs from 'qs';
125125

126126
export default defineComponent({
127-
setup () {
128-
const { route } = useRouter()
127+
setup() {
128+
const { route } = useRouter();
129129

130-
const service = route.value.params.service
131-
console.log('service:', service)
130+
const service = route.value.params.service;
131+
console.log('service:', service);
132132

133133
onMounted(() => {
134-
const queryParams = qs.parse(window.location.search, { ignoreQueryPrefix: true })
134+
const queryParams = qs.parse(window.location.search, { ignoreQueryPrefix: true });
135135

136-
const loginChannel = new BroadcastChannel('oauthLoginChannel')
137-
loginChannel.postMessage(queryParams.code) // send the code
138-
loginChannel.close()
139-
window.close()
140-
})
136+
const loginChannel = new BroadcastChannel('oauthLoginChannel');
137+
loginChannel.postMessage(queryParams.code); // send the code
138+
loginChannel.close();
139+
window.close();
140+
});
141141

142-
return { ...toRefs(data), service }
143-
}
144-
})
142+
return { ...toRefs(data), service };
143+
},
144+
});
145145
```
146146

147147
### Create the provider definition
148148

149149
In the `oauthLoginChannel.onmessage` handler, we called:
150+
150151
```typescript
151-
accountsClient.loginWithService('oauth', { provider: 'nextcloud', code })
152+
accountsClient.loginWithService('oauth', { provider: 'nextcloud', code });
152153
```
153154

154155
AccountsJS client will send that code to the server, where define a provider:
155156

156157
```typescript
157158
const accountsOauth = new AccountsOauth({
158159
nextcloud: new AccountsNextcloudProvider(),
159-
})
160+
});
160161
```
161162

162163
The provider is defined like this:
164+
163165
```typescript
164166
export class AccountsNextcloudProvider implements OAuthProvider {
165-
166167
/* This method is called when the user returns from the provider with an authorization code */
167168
async authenticate(params: any): Promise<OAuthUser> {
168-
// params.code is the auth code that nextcloud OAuth provides to the client
169+
// params.code is the auth code that nextcloud OAuth provides to the client
169170
// then LoginDialog sends the code here via accountsClient.loginWithService
170171
// it is used here to authenticate against nextcloud and to get the user info
171-
172+
172173
// Ask Nextcloud server if the code is valid, and which user it authenticates
173174
const response = await axios.post(
174175
config.get('accounts.oauth.nextcloud.token-endpoint'), // see: https://docs.nextcloud.com/server/19/admin_manual/configuration_server/oauth2.html
@@ -182,12 +183,12 @@ export class AccountsNextcloudProvider implements OAuthProvider {
182183
headers: {
183184
'Content-Type': 'application/x-www-form-urlencoded',
184185
},
185-
},
186-
)
186+
}
187+
);
187188

188-
const data = response.data
189-
const token: string = data.access_token
190-
const userID: string = data.user_id
189+
const data = response.data;
190+
const token: string = data.access_token;
191+
const userID: string = data.user_id;
191192

192193
// Optional - query Nextcloud for additional user info:
193194

@@ -209,19 +210,19 @@ export class AccountsNextcloudProvider implements OAuthProvider {
209210
// This data will be passed to the getRegistrationPayload below, and to createJwtPayload (see optional step later)
210211
return {
211212
id: userID,
212-
//data: userMeta, isAdmin, groups,
213-
}
213+
//data: userMeta, isAdmin, groups,
214+
};
214215
}
215216

216217
/* If your server doesn't know the user yet, this method will be called to get initial user info to be stored in the DB */
217218
async getRegistrationPayload(oauthUser: OAuthUser): Promise<any> {
218-
console.log('OAuth Registration payload for:', oauthUser)
219+
console.log('OAuth Registration payload for:', oauthUser);
219220
return {
220221
// This is nextcloud-specific - TODO: Adapt to your provider
221222
// username: oauthUser.data.id,
222223
// email: oauthUser.data.email,
223224
// displayName: oauthUser.data.displayname,
224-
}
225+
};
225226
}
226227
}
227228
```
@@ -230,7 +231,6 @@ export class AccountsNextcloudProvider implements OAuthProvider {
230231

231232
This should be enough for a basic OAuth setup to work.
232233

233-
234234
## Optional: Extend the JWT token
235235

236236
In order to add custom fields to the JWT you need to pass a validateNewUser function when you instantiate the `@accounts/password` package.
@@ -241,7 +241,7 @@ new AccountsServer<ExtendedUserType>(
241241
createJwtPayload: async (data, user) => {
242242
// data is the object returned from AccountsNextcloudProvider.authenticate
243243
// user is the user fetched from the db
244-
244+
245245
const nextcloudData = _.get(user.services, 'nextcloud')
246246
if (!nextcloudData) {
247247
console.log('Extending JWT skipped - no Nextcloud data') // seems to be called sometimes without the data
@@ -259,4 +259,3 @@ new AccountsServer<ExtendedUserType>(
259259
//... services config
260260
)
261261
```
262-

0 commit comments

Comments
 (0)