Skip to content

Instantly share code, notes, and snippets.

@fermuch
Created February 27, 2018 19:31
Show Gist options
  • Save fermuch/e9952528ae635bb13cbb5970befb72d2 to your computer and use it in GitHub Desktop.
Save fermuch/e9952528ae635bb13cbb5970befb72d2 to your computer and use it in GitHub Desktop.
import {getSchema} from 'graphql-loader';
import {initAccounts} from 'meteor/nicolaslopezj:apollo-accounts';
import {addGraphQLSchema, addGraphQLResolvers, addGraphQLMutation} from 'meteor/vulcan:lib';
initAccounts({
loginWithFacebook: false,
loginWithGoogle: false,
loginWithLinkedIn: false,
loginWithPassword: true
});
// if we could get graphql-loader's store, we could use it directly without making our own
// definitions. Maybe make a PR?
const accountsSchema = `
type LoginMethodResponse {
# Id of the user logged in user
id: String!
# Token of the connection
token: String!
# Expiration date for the token
tokenExpires: Float!
# The logged in user
user: User
}
input CreateUserProfileInput {
name: String
}
type SuccessResponse {
# True if it succeeded
success: Boolean
}
input HashedPassword {
# The hashed password
digest: String!
# Algorithm used to hash the password
algorithm: String!
}
`;
const accountsMutations = `
# Log the user in with a password.
loginWithPassword(
username: String,
email: String,
password: HashedPassword,
plainPassword: String
): LoginMethodResponse
# Create a new user.
createUser(
username: String,
email: String,
password: HashedPassword,
plainPassword: String,
profile: CreateUserProfileInput
): LoginMethodResponse
# Change the current user's password. Must be logged in.
changePassword(
oldPassword: HashedPassword!,
newPassword: HashedPassword!
): SuccessResponse
# Request a forgot password email.
forgotPassword (email: String!): SuccessResponse
# Reset the password for a user using a token received in email. Logs the user in afterwards.
resetPassword (newPassword: HashedPassword!, token: String!): LoginMethodResponse
# Log the user out.
logout (token: String!): SuccessResponse
# Marks the user's email address as verified. Logs the user in afterwards.
verifyEmail (token: String!): LoginMethodResponse
# Send an email with a link the user can use verify their email address.
resendVerificationEmail (email: String): SuccessResponse
`;
const schema = getSchema();
addGraphQLSchema(accountsSchema);
addGraphQLMutation(accountsMutations);
addGraphQLResolvers(schema.resolvers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment