
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@accounts/graphql-api
Advanced tools
Schema, Resolvers and Utils for GraphQL server with JSAccounts
This package does not requires any network interface / express in order to combine with your GraphQL - it's just a collection of GraphQL schema, resolvers and utils!
This package exports GraphQL schema and GraphQL resolvers, which you can extend with your existing GraphQL schema server.
Start by installing it from NPM / Yarn:
// Npm
npm install --save @accounts/server @accounts/graphql-api
// Yarn
yarn add @accounts/server @accounts/graphql-api
This package does not create a transport or anything else, only schema and string and resolvers as object.
Start by configuring your AccountsServer as you wish. For example, using MongoDB:
import mongoose from 'mongoose'
import AccountsServer from '@accounts/server'
import AccountsPassword from '@accounts/password'
import MongoDBInterface from '@accounts/mongo'
const db = mongoose.connection
const password = new AccountsPassword()
const accountsServer = new AccountsServer({
{
db: new MongoDBInterface(db),
tokenSecret: 'SECRET',
},
{
password,
}
});
Next, import createAccountsGraphQL method from this package, and run it with your AccountsServer:
import { createAccountsGraphQL } from '@accounts/graphql-api';
const accountsGraphQL = createAccountsGraphQL(accountsServer);
Now, add accountsGraphQL.typeDefs to your schema definition (just before using it with makeExecutableSchema), and extend your resolvers object with accountsGraphQL.resolvers, for example:
import { makeExecutableSchema } from 'graphql-tools';
import { merge } from 'lodash';
const typeDefs = [
`
type Query {
myQuery: String
}
type Mutation {
myMutation: String
}
schema {
query: Query,
mutation: Mutation
}
`,
accountsGraphQL.typeDefs,
];
let myResolvers = {
Query: {
myQuery: () => 'Hello',
},
Mutation: {
myMutation: () => 'Hello',
},
};
const schema = makeExecutableSchema({
resolvers: merge(accountsGraphQL.resolvers, myResolvers),
typeDefs,
});
The last step is to extend your graphqlExpress with a context middleware, that extracts the authentication token from the HTTP request, so AccountsServer will automatically validate it:
import { accountsContext } from '@accounts/graphql-api';
app.use(
GRAPHQL_ROUTE,
bodyParser.json(),
graphqlExpress(request => {
return {
context: {
...accountsContext(request),
// your context
},
schema,
};
})
);
You can authenticate your own resolvers with JSAccounts authentication flow, by using authenticated method from this package.
This method composer also extends context with the current authenticated user!
This is an example for a protected mutation:
import AccountsServer from '@accounts/server';
import { authenticated } from '@accounts/graphql-api';
export const resolver = {
Mutation: {
updateUserProfile: authenticated(AccountsServer, (rootValue, args, context) => {
// Write your resolver here
// context.user - the current authenticated user!
}),
},
};
This package allow you to customize the GraphQL schema and it's resolvers.
For example, some application main query called MyQuery or RootQuery instead of query, so you can customize the name, without modifying you application's schema.
These are the available customizations:
rootQueryName (string) - The name of the root query, default: Query.rootMutationName (string) - The name of the root mutation, default: Mutation.extend (boolean) - whether to add extend before the root type declaration, default: true.withSchemaDefinition (boolean): whether to add schema { ... } declaration to the generation schema, default: false.Pass a second object to createAccountsGraphQL, for example:
const myCustomGraphQLAccounts = createSchemaWithAccounts(accountsServer, {
rootQueryName: 'RootQuery',
rootMutationName: 'RootMutation',
});
Another possible customization is to modify the name of the authentication header, use it with accountsContext (the default is Authorization):
context: accountsContext(request, 'MyCustomHeader');
UserTo extend User object with custom fields and logic, add your own GraphQL type definition of User with the prefix of extend, and add your fields:
extend type User {
firstName: String
lastName: String
}
And also implement a regular resolver, for the fields you added:
const UserResolver = {
firstName: () => 'Dotan',
lastName: () => 'Simha',
};
User during password creationTo extend the user object during the user creation you need to extend the CreateUserInput type and add your fields:
extend input CreateUserInput {
profile: CreateUserProfileInput!
}
input CreateUserProfileInput {
firstName: String!
lastName: String!
}
The user will be saved in the db with the profile key set.
FAQs
Server side GraphQL transport for accounts
The npm package @accounts/graphql-api receives a total of 1,982 weekly downloads. As such, @accounts/graphql-api popularity was classified as popular.
We found that @accounts/graphql-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.