Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
extends: 'airbnb-base',
parserOptions: {
ecmaVersion: 6,
},
plugins: ['import'],

rules: {
'comma-dangle': 1,
'no-param-reassign': [1, { props: false }],
'arrow-parens': 0,
'import/extensions': 'off',
'import/no-unresolved': 'off',
'no-plusplus': 0,
'no-console': 0,
'no-confusing-arrow': 0,
'import/no-extraneous-dependencies': 0,
'react/require-extension': 'off',
'react/prefer-stateless-function': 'off',
'no-trailing-spaces': [2, { skipBlankLines: true }],
'react/forbid-prop-types': 0,
'no-unused-expressions': [1, { allowTernary: true }],
'max-len': [
2,
{
code: 120,
ignoreStrings: true,
ignoreTemplateLiterals: true,
},
],
},
};
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
"graphql-tools": "^2.24.0",
"graphql-type-json": "^0.2.0",
"graphql-yoga": "^1.8.0",
"hubspot-api": "^1.0.1",
"hubspot-api": "^1.3.0",
"moment": "^2.22.0",
"nodemon": "^1.17.3"
},
"devDependencies": {
"eslint": "^5.5.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.14.0"
}
}
96 changes: 57 additions & 39 deletions query-resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ const assertHasCredentials = ctx => {
}
};

const flattenProps = properties => Object.keys(properties).reduce((acc, curr) => {
acc[curr] = properties[curr].value;
return acc;
}, {});
const flattenProps = properties =>
Object.keys(properties).reduce((acc, curr) => {
acc[curr] = properties[curr].value;
return acc;
}, {});

const contactsResponse = contact => {
const {vid, properties} = contact;
return Object.assign({
vid
}, flattenProps(properties));
const { vid, properties } = contact;
return Object.assign({ vid }, flattenProps(properties));
};

const companiesResponse = company => {
const {portalId, properties, additionalDomains} = company;
return Object.assign({
portalId,
properties
}, flattenProps(properties));
const { portalId, properties, additionalDomains } = company;
return Object.assign(
{
portalId,
properties,
},
flattenProps(properties),
);
};

module.exports = {
version: (_, opts, context) => {
return pjs.version;
},
version: (_, opts, context) => pjs.version,
contacts: async (_, opts, context) => {
assertHasCredentials(context);
const {hs} = context;
const { hs } = context;
// Define extra properties as required by the schema
const property = ['email', 'firstname', 'lastname', 'company'];
Object.assign(opts, {property});
Object.assign(opts, { property });
const response = await hs.contacts.getContacts(opts);
const {contacts} = response;
const { contacts } = response;
return contacts.map(contactsResponse);
},
contact: async (_, opts, context) => {
assertHasCredentials(context);
const {hs} = context;
const {id, email, utk} = opts;
const { hs } = context;
const { id, email, utk } = opts;
let response;
if (id) {
response = await hs.contacts.getById(id);
Expand All @@ -55,65 +55,83 @@ module.exports = {
} else {
throw new Error('You must specify one of `id`, `email`, `utk` in your query');
}
const {vid, properties} = response;
const { vid, properties } = response;
return contactsResponse(response);
},
blogAuthor: async (_, opts, context) => {
assertHasCredentials(context);
const {hs} = context;
const { hs } = context;
const response = await hs.blog.getAuthor(opts.id);
return response;
},
blogAuthors: async (_, opts, context) => {
assertHasCredentials(context);
const {hs} = context;
const { hs } = context;
const response = await hs.blog.getAuthors(opts);
const {objects} = response;
const { objects } = response;
return objects;
},
page: async (_, opts, context, {cacheControl}) => {
page: async (_, opts, context, { cacheControl }) => {
assertHasCredentials(context);
const {hs} = context;
const { hs } = context;
const response = await hs.pages.getPageById(opts.id);
return response;
},
pages: async (_, opts, context, {cacheControl}) => {
pages: async (_, opts, context, { cacheControl }) => {
assertHasCredentials(context);
const {hs} = context;
const { hs } = context;
const response = await hs.pages.getPages(opts);
const {objects} = response;
const { objects } = response;
return objects;
},
tables: async (_, opts, context, { cacheControl }) => {
assertHasCredentials(context);
const { hs } = context;
const response = await hs.hubdb.getTables(opts);
const { objects } = response;
return objects;
},
rows: async (_, opts, context, { cacheControl }) => {
assertHasCredentials(context);
const { hs } = context;
const response = await hs.hubdb.getTableRows(opts.tableId, opts.portalId);
const { objects } = response;
return objects;
},
blogPost: async (_, opts, context) => {
assertHasCredentials(context);
const {hs} = context;
const { hs } = context;
const response = await hs.blog.getPostById(opts);
return response;
},
blogPosts: async (_, opts, context) => {
const {contentGroupId: content_group_id, blogAuthorId: blog_author_id, limit} = opts;
const { contentGroupId: content_group_id, blogAuthorId: blog_author_id, limit } = opts;

assertHasCredentials(context);
const {hs} = context;
const response = await hs.blog.getPosts({content_group_id, blog_author_id, limit});
const {objects} = response;
const { hs } = context;
const response = await hs.blog.getPosts({
content_group_id,
blog_author_id,
limit,
});
const { objects } = response;
return objects;
},
workflows: async (_, opts, context) => {
assertHasCredentials(context);
const {hs} = context;
const { hs } = context;
const response = await hs.workflows.getAll();
const {workflows} = response;
const { workflows } = response;

// Filtering (as this is not provided by the API)

return workflows;
},
workflow: async (_, opts, context) => {
assertHasCredentials(context);
const {hs} = context;
const { hs } = context;
const response = await hs.workflows.getWorkflow(opts.id);
debug(response);
return response;
}
},
};
Loading