Skip to content

Commit

Permalink
fix: fix impersonation mutation to use userFieldsFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
NickBolles committed Oct 22, 2019
1 parent cfb0004 commit 429865e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
29 changes: 15 additions & 14 deletions packages/graphql-client/src/graphql-client.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { TransportInterface, AccountsClient } from '@accounts/client';
import { CreateUser, LoginResult, ImpersonationResult, User } from '@accounts/types';
import { AccountsClient, TransportInterface } from '@accounts/client';
import { CreateUser, ImpersonationResult, LoginResult, User } from '@accounts/types';
import gql from 'graphql-tag';
import { authenticateWithServiceMutation } from './graphql/authenticate-with-service.mutation';
import { changePasswordMutation } from './graphql/change-password.mutation';
import { createUserMutation } from './graphql/create-user.mutation';
import { getTwoFactorSecretQuery } from './graphql/get-two-factor-secret.query';
import { getUserQuery } from './graphql/get-user.query';
import { impersonateMutation } from './graphql/impersonate.mutation';
import { loginWithServiceMutation } from './graphql/login-with-service.mutation';
import { authenticateWithServiceMutation } from './graphql/authenticate-with-service.mutation';
import { logoutMutation } from './graphql/logout.mutation';
import { refreshTokensMutation } from './graphql/refresh-tokens.mutation';
import { verifyEmailMutation } from './graphql/verify-email.mutation';
import { resetPasswordMutation } from './graphql/reset-password.mutation';
import { sendResetPasswordEmailMutation } from './graphql/send-reset-password-email.mutation';
import { sendVerificationEmailMutation } from './graphql/send-verification-email.mutation';
import { resetPasswordMutation } from './graphql/reset-password.mutation';
import { changePasswordMutation } from './graphql/change-password.mutation';
import { twoFactorSetMutation } from './graphql/two-factor-set.mutation';
import { getTwoFactorSecretQuery } from './graphql/get-two-factor-secret.query';
import { twoFactorUnsetMutation } from './graphql/two-factor-unset.mutation';
import { impersonateMutation } from './graphql/impersonate.mutation';
import { getUserQuery } from './graphql/get-user.query';
import gql from 'graphql-tag';
import { verifyEmailMutation } from './graphql/verify-email.mutation';

export interface IAuthenticateParams {
[key: string]: string | object;
Expand Down Expand Up @@ -154,19 +154,20 @@ export default class GraphQLClient implements TransportInterface {
public async impersonate(
token: string,
impersonated: {
userId?: string;
username?: string;
email?: string;
/* These aren't implemented in graphql-api, comment them out for now to avoid confusion */
// userId?: string;
// email?: string;
}
): Promise<ImpersonationResult> {
return this.mutate(impersonateMutation, 'impersonate', {
return this.mutate(impersonateMutation(this.options.userFieldsFragment), 'impersonate', {
accessToken: token,
username: impersonated.username,
});
}

private async mutate(mutation: any, resultField: any, variables: any = {}) {
// If we are executiong a refresh token mutation do not call refress session again
// If we are executing a refresh token mutation do not call refresh session again
// otherwise it will end up in an infinite loop
const tokens =
mutation === refreshTokensMutation
Expand Down
8 changes: 3 additions & 5 deletions packages/graphql-client/src/graphql/impersonate.mutation.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import gql from 'graphql-tag';

export const impersonateMutation = gql`
export const impersonateMutation = (userFieldsFragment: any) => gql`
${userFieldsFragment}
mutation impersonate($accessToken: String!, $username: String!) {
impersonate(accessToken: $accessToken, username: $username) {
authorized
tokens {
refreshToken
accessToken
}
# // TODO: Extract user into a fragment
user {
id
email
username
...userFields
}
}
}
Expand Down

0 comments on commit 429865e

Please sign in to comment.