Skip to content
This repository has been archived by the owner on Aug 14, 2021. It is now read-only.

Commit

Permalink
Move signInEmail query to mutation with lacking useLazyQuery
Browse files Browse the repository at this point in the history
- Currently, useLazyQuery does not return promises apollographql/react-apollo#3499.
  • Loading branch information
hyochan committed Jan 26, 2020
1 parent 9515590 commit d6a3cde
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ type Query {
users(includeUser: Boolean): [User!]!
user(id: ID!): User
me: User
signInEmail(email: String! password: String!): AuthPayload!
findPassword(email: String!): Boolean
messages: [Message!]!
channels: [Channel!]!
friends: [Friend!]!
}

type Mutation {
signInEmail(email: String! password: String!): AuthPayload!
signInGoogle(socialUser: SocialUserInput!): AuthPayload!
signInFacebook(socialUser: SocialUserInput!): AuthPayload!
signInApple(socialUser: SocialUserInput!): AuthPayload!
Expand Down
20 changes: 10 additions & 10 deletions src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type Message = {

export type Mutation = {
__typename?: 'Mutation',
signInEmail: AuthPayload,
signInGoogle: AuthPayload,
signInFacebook: AuthPayload,
signInApple: AuthPayload,
Expand All @@ -99,6 +100,12 @@ export type Mutation = {
};


export type MutationSignInEmailArgs = {
email: Scalars['String'],
password: Scalars['String']
};


export type MutationSignInGoogleArgs = {
socialUser: SocialUserInput
};
Expand Down Expand Up @@ -160,7 +167,6 @@ export type Query = {
users: Array<User>,
user?: Maybe<User>,
me?: Maybe<User>,
signInEmail: AuthPayload,
findPassword?: Maybe<Scalars['Boolean']>,
messages: Array<Message>,
channels: Array<Channel>,
Expand All @@ -178,12 +184,6 @@ export type QueryUserArgs = {
};


export type QuerySignInEmailArgs = {
email: Scalars['String'],
password: Scalars['String']
};


export type QueryFindPasswordArgs = {
email: Scalars['String']
};
Expand Down Expand Up @@ -350,9 +350,9 @@ export type ResolversTypes = {
Membership: ResolverTypeWrapper<Membership>,
MemberType: MemberType,
UserModeType: UserModeType,
AuthPayload: ResolverTypeWrapper<AuthPayload>,
Friend: ResolverTypeWrapper<Friend>,
Mutation: ResolverTypeWrapper<{}>,
AuthPayload: ResolverTypeWrapper<AuthPayload>,
SocialUserInput: SocialUserInput,
UserInput: UserInput,
NotificationCreateInput: NotificationCreateInput,
Expand All @@ -377,9 +377,9 @@ export type ResolversParentTypes = {
Membership: Membership,
MemberType: MemberType,
UserModeType: UserModeType,
AuthPayload: AuthPayload,
Friend: Friend,
Mutation: {},
AuthPayload: AuthPayload,
SocialUserInput: SocialUserInput,
UserInput: UserInput,
NotificationCreateInput: NotificationCreateInput,
Expand Down Expand Up @@ -444,6 +444,7 @@ export type MessageResolvers<ContextType = MyContext, ParentType extends Resolve
};

export type MutationResolvers<ContextType = MyContext, ParentType extends ResolversParentTypes['Mutation'] = ResolversParentTypes['Mutation']> = {
signInEmail?: Resolver<ResolversTypes['AuthPayload'], ParentType, ContextType, RequireFields<MutationSignInEmailArgs, 'email' | 'password'>>,
signInGoogle?: Resolver<ResolversTypes['AuthPayload'], ParentType, ContextType, RequireFields<MutationSignInGoogleArgs, 'socialUser'>>,
signInFacebook?: Resolver<ResolversTypes['AuthPayload'], ParentType, ContextType, RequireFields<MutationSignInFacebookArgs, 'socialUser'>>,
signInApple?: Resolver<ResolversTypes['AuthPayload'], ParentType, ContextType, RequireFields<MutationSignInAppleArgs, 'socialUser'>>,
Expand All @@ -467,7 +468,6 @@ export type QueryResolvers<ContextType = MyContext, ParentType extends Resolvers
users?: Resolver<Array<ResolversTypes['User']>, ParentType, ContextType, QueryUsersArgs>,
user?: Resolver<Maybe<ResolversTypes['User']>, ParentType, ContextType, RequireFields<QueryUserArgs, 'id'>>,
me?: Resolver<Maybe<ResolversTypes['User']>, ParentType, ContextType>,
signInEmail?: Resolver<ResolversTypes['AuthPayload'], ParentType, ContextType, RequireFields<QuerySignInEmailArgs, 'email' | 'password'>>,
findPassword?: Resolver<Maybe<ResolversTypes['Boolean']>, ParentType, ContextType, RequireFields<QueryFindPasswordArgs, 'email'>>,
messages?: Resolver<Array<ResolversTypes['Message']>, ParentType, ContextType>,
channels?: Resolver<Array<ResolversTypes['Channel']>, ParentType, ContextType>,
Expand Down
54 changes: 27 additions & 27 deletions src/resolvers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,6 @@ const resolver: Resolvers = {

return User.findOne({ where: args });
},
signInEmail: async (_, args, { models, appSecret, pubsub }): Promise<AuthPayload> => {
const { User: userModel } = models;

const user = await userModel.findOne({
where: {
email: args.email,
},
raw: true,
});

if (!user) throw new AuthenticationError('User does not exsists');

const validate = await validateCredential(args.password, user.password);

if (!validate) throw new AuthenticationError('Password is not correct');

const token: string = jwt.sign(
{
userId: user.id,
role: Role.User,
},
appSecret,
);

pubsub.publish(USER_SIGNED_IN, { userSignedIn: user });
return { token, user };
},
findPassword: async (_, args): Promise<boolean> => {
const email = args.email;

Expand Down Expand Up @@ -153,6 +126,33 @@ your password will reset to <strong>dooboolab2017</strong>.
},
},
Mutation: {
signInEmail: async (_, args, { models, appSecret, pubsub }): Promise<AuthPayload> => {
const { User: userModel } = models;

const user = await userModel.findOne({
where: {
email: args.email,
},
raw: true,
});

if (!user) throw new AuthenticationError('User does not exsists');

const validate = await validateCredential(args.password, user.password);

if (!validate) throw new AuthenticationError('Password is not correct');

const token: string = jwt.sign(
{
userId: user.id,
role: Role.User,
},
appSecret,
);

pubsub.publish(USER_SIGNED_IN, { userSignedIn: user });
return { token, user };
},
signInGoogle: async (_, { socialUser }, { appSecret, models }): Promise<AuthPayload> =>
signInWithSocialAccount(socialUser, models, appSecret),

Expand Down

0 comments on commit d6a3cde

Please sign in to comment.