https://github.com/studiointeract/apollo-accounts
Accounts for Apollo (GraphQL)
https://github.com/studiointeract/apollo-accounts
Last synced: 4 months ago
JSON representation
Accounts for Apollo (GraphQL)
- Host: GitHub
- URL: https://github.com/studiointeract/apollo-accounts
- Owner: studiointeract
- Created: 2016-12-18T21:23:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-19T00:13:35.000Z (over 8 years ago)
- Last Synced: 2025-01-05T22:26:37.384Z (6 months ago)
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Accounts for Apollo (GraphQL)
## Typedefs
http://dev.apollodata.com/tools/graphql-tools/generate-schema.html#modularizing
```js
import gql from 'graphql-tag';
import { Email } from 'apollo-accounts-password/typedefs';
import { Facebook } from 'apollo-accounts-facebook/typedefs';const User = gql`
type User {
_id: ID!
emails: [Email]
facebook: Facebook
}
`;const Mutation = gql`
mutation Mutation {
signUpWithPassword(
email: String!
password: String!
): UsersignInWithPassword(
email: String!
password: String!
): UsersignUpWithFacebook(
accessToken: String!
expiresAt: String!
): User
}
`;const Query = gql`
type Query {
user: User
}
`;const Schema = gql`
schema {
query: Query
mutation: Mutation
}`;export default () => [
User,
Email,
Facebook,
InputEmail,
InputPassword,
Query,
Mutation,
Schema,
];
```## Resolvers
```js
import uuid from 'uuid/v4';
import {
signUpWithPassword,
signInWithPassword,
validatePassword,
} from 'apollo-accounts-password';
import {
Facebook,
signUpWithFacebook,
} from 'apollo-accounts-facebook';const resolveFunctions = {
Query: {
user(root, args, { user }) {
return user;
},
},Mutation: {
signUpWithPassword(...args) {
const { email, services } = signUpWithPassword({ ...args });
// Store the user somewhere and save the service settings.
const user = {
_id: uuid,
services,
emails: [ email ],
};
Collection.insert(user);
return user;
},signInWithPassword(...args) {
const { email, services } = signInWithPassword({ ...args });
const user = Collection.findOne({ email });
if (validatePassword({ user, ...args })) {
return user;
}
},async signUpWithFacebook(...args) {
const {
services,
fields: {
first_name,
last_name,
},
} = await signUpWithFacebook({
...args,
fields: {
first_name: 1,
last_name: 1,
},
});
// Store the user somewhere and save the service settings.
const user = {
_id: uuid(),
services,
first_name,
last_name,
};
Collection.insert(user);
return user;
},
},User: {
emails: ({ emails }) => emails,
facebook: ({ userId, first_name, last_name }) => ({
userId, first_name, last_name,
}),
},FacebookUser,
};
```## Middlewares
```js
import {
resumeWithToken,
validateToken,
} from 'apollo-accounts';```