Skip to content

Commit

Permalink
fix(deps): add lru-cache as explicit dependency (#250)
Browse files Browse the repository at this point in the history
Fixes #245

Took the opportunity to upgrade a bunch of deps too

... which cascaded to a bunch of lint fixes also.
  • Loading branch information
benjie committed Jul 14, 2018
1 parent 22aaa29 commit a65cdc5
Show file tree
Hide file tree
Showing 42 changed files with 851 additions and 600 deletions.
1 change: 0 additions & 1 deletion .eslintignore
@@ -1,5 +1,4 @@
node_modules
node7minus
node8plus
__tests__
examples
3 changes: 3 additions & 0 deletions .eslintrc.js
Expand Up @@ -10,6 +10,9 @@ module.exports = {
node: true,
es6: true,
},
globals: {
jasmine: false,
},
rules: {
"prettier/prettier": [
"error",
Expand Down
68 changes: 46 additions & 22 deletions packages/graphile-build-pg/__tests__/tags.test.js
@@ -1,25 +1,49 @@
const { parseTags } = require("../src/utils");

test('tags are removed correctly', () => {
expect(parseTags(`@deprecated Persons now have first and last name\nThe person's name`).text).toBe(`The person's name`)
expect(parseTags(`@deprecated Persons now have first and last name`).text).toBe(``)
expect(parseTags(`@foo\n@bar\nBaz`).text).toBe(`Baz`)
expect(parseTags(` @foo @bar\nBaz`).text).toBe(` @foo @bar\nBaz`)
expect(parseTags(`@foo\n @bar\nBaz`).text).toBe(` @bar\nBaz`)
expect(parseTags(`@foo@bar Baz`).text).toBe(`@foo@bar Baz`)
expect(parseTags(`Blah blah @deprecated`).text).toBe(`Blah blah @deprecated`)
expect(parseTags(`Blah blah\n@deprecated`).text).toBe(`Blah blah\n@deprecated`)
expect(parseTags(`@jsonField date timestamp\n@jsonField name text\n@jsonField episode enum ONE=1 TWO=2\nBaz`).text).toBe(`Baz`)

test("tags are removed correctly", () => {
expect(
parseTags(
`@deprecated Persons now have first and last name\nThe person's name`
).text
).toBe(`The person's name`);
expect(
parseTags(`@deprecated Persons now have first and last name`).text
).toBe(``);
expect(parseTags(`@foo\n@bar\nBaz`).text).toBe(`Baz`);
expect(parseTags(` @foo @bar\nBaz`).text).toBe(` @foo @bar\nBaz`);
expect(parseTags(`@foo\n @bar\nBaz`).text).toBe(` @bar\nBaz`);
expect(parseTags(`@foo@bar Baz`).text).toBe(`@foo@bar Baz`);
expect(parseTags(`Blah blah @deprecated`).text).toBe(`Blah blah @deprecated`);
expect(parseTags(`Blah blah\n@deprecated`).text).toBe(
`Blah blah\n@deprecated`
);
expect(
parseTags(
`@jsonField date timestamp\n@jsonField name text\n@jsonField episode enum ONE=1 TWO=2\nBaz`
).text
).toBe(`Baz`);
});

test('tags are extracted correctly', () => {
expect(parseTags(`@deprecated Persons now have first and last name\nThe person's name`).tags).toEqual({deprecated: "Persons now have first and last name"})
expect(parseTags(`@deprecated Persons now have first and last name`).tags).toEqual({deprecated: "Persons now have first and last name"})
expect(parseTags(`@foo\n@bar\nBaz`).tags).toEqual({foo: true, bar: true})
expect(parseTags(` @foo @bar\nBaz`).tags).toEqual({})
expect(parseTags(`@foo\n @bar\nBaz`).tags).toEqual({foo: true})
expect(parseTags(`@foo@bar Baz`).tags).toEqual({})
expect(parseTags(`Blah blah @deprecated`).tags).toEqual({})
expect(parseTags(`Blah blah\n@deprecated`).tags).toEqual({})
expect(parseTags(`@jsonField date timestamp\n@jsonField name text\n@jsonField episode enum ONE=1 TWO=2\nBaz`).tags).toEqual({jsonField: ["date timestamp", "name text", "episode enum ONE=1 TWO=2"]})
});
test("tags are extracted correctly", () => {
expect(
parseTags(
`@deprecated Persons now have first and last name\nThe person's name`
).tags
).toEqual({ deprecated: "Persons now have first and last name" });
expect(
parseTags(`@deprecated Persons now have first and last name`).tags
).toEqual({ deprecated: "Persons now have first and last name" });
expect(parseTags(`@foo\n@bar\nBaz`).tags).toEqual({ foo: true, bar: true });
expect(parseTags(` @foo @bar\nBaz`).tags).toEqual({});
expect(parseTags(`@foo\n @bar\nBaz`).tags).toEqual({ foo: true });
expect(parseTags(`@foo@bar Baz`).tags).toEqual({});
expect(parseTags(`Blah blah @deprecated`).tags).toEqual({});
expect(parseTags(`Blah blah\n@deprecated`).tags).toEqual({});
expect(
parseTags(
`@jsonField date timestamp\n@jsonField name text\n@jsonField episode enum ONE=1 TWO=2\nBaz`
).tags
).toEqual({
jsonField: ["date timestamp", "name text", "episode enum ONE=1 TWO=2"],
});
});
2 changes: 1 addition & 1 deletion packages/graphile-build-pg/package.json
Expand Up @@ -40,7 +40,7 @@
"graphql-iso-date": "^3.2.0",
"jsonwebtoken": "^8.1.1",
"lodash": ">=4 <5",
"lru-cache": "4.1.1",
"lru-cache": ">=4 <5",
"pg-sql2": "2.1.0",
"postgres-interval": "1.1.1"
},
Expand Down
9 changes: 7 additions & 2 deletions packages/graphile-build-pg/src/plugins/PgAllRows.js
Expand Up @@ -26,7 +26,10 @@ export default (async function PgAllRows(
pgAddStartEndCursor: addStartEndCursor,
pgOmit: omit,
} = build;
const { fieldWithHooks, scope: { isRootQuery } } = context;
const {
fieldWithHooks,
scope: { isRootQuery },
} = context;
if (!isRootQuery) {
return fields;
}
Expand Down Expand Up @@ -144,7 +147,9 @@ export default (async function PgAllRows(
if (debugSql.enabled) debugSql(text);
const result = await pgClient.query(text, values);
if (isConnection) {
const { rows: [row] } = result;
const {
rows: [row],
} = result;
return addStartEndCursor(row);
} else {
return result.rows;
Expand Down
Expand Up @@ -7,7 +7,11 @@ export default (function PgConnectionArgs(builder) {
builder.hook(
"GraphQLObjectType:fields:field:args",
(args, build, context) => {
const { extend, getTypeByName, graphql: { GraphQLInt } } = build;
const {
extend,
getTypeByName,
graphql: { GraphQLInt },
} = build;
const {
scope: {
isPgFieldConnection,
Expand Down
Expand Up @@ -94,7 +94,9 @@ export default (function PgConnectionArgOrderBy(builder) {

addArgDataGenerator(function connectionOrderBy({ orderBy: rawOrderBy }) {
const orderBy = rawOrderBy
? Array.isArray(rawOrderBy) ? rawOrderBy : [rawOrderBy]
? Array.isArray(rawOrderBy)
? rawOrderBy
: [rawOrderBy]
: null;
return {
pgCursorPrefix: cursorPrefixFromOrderBy(orderBy),
Expand Down
Expand Up @@ -3,7 +3,11 @@ import type { Plugin } from "graphile-build";

export default (function PgConnectionTotalCount(builder) {
builder.hook("GraphQLObjectType:fields", (fields, build, context) => {
const { extend, inflection, graphql: { GraphQLInt } } = build;
const {
extend,
inflection,
graphql: { GraphQLInt },
} = build;
const {
scope: { isPgRowConnectionType, pgIntrospection: table },
fieldWithHooks,
Expand Down
Expand Up @@ -33,7 +33,10 @@ export default (function PgMutationCreatePlugin(
pgOmit: omit,
pgViaTemporaryTable: viaTemporaryTable,
} = build;
const { scope: { isRootMutation }, fieldWithHooks } = context;
const {
scope: { isRootMutation },
fieldWithHooks,
} = context;
if (!isRootMutation) {
return fields;
}
Expand Down
Expand Up @@ -67,7 +67,9 @@ export default (function PgMutationPayloadEdgePlugin(builder) {
}) {
const orderBy =
canOrderBy && rawOrderBy
? Array.isArray(rawOrderBy) ? rawOrderBy : [rawOrderBy]
? Array.isArray(rawOrderBy)
? rawOrderBy
: [rawOrderBy]
: null;
return {
pgQuery: queryBuilder => {
Expand Down Expand Up @@ -142,7 +144,9 @@ export default (function PgMutationPayloadEdgePlugin(builder) {
resolve(data, { orderBy: rawOrderBy }) {
const orderBy =
canOrderBy && rawOrderBy
? Array.isArray(rawOrderBy) ? rawOrderBy : [rawOrderBy]
? Array.isArray(rawOrderBy)
? rawOrderBy
: [rawOrderBy]
: null;
const order =
orderBy && orderBy.some(item => item.alias)
Expand Down
Expand Up @@ -11,7 +11,10 @@ export default (function PgMutationProceduresPlugin(builder) {
pgOmit: omit,
swallowError,
} = build;
const { scope: { isRootMutation }, fieldWithHooks } = context;
const {
scope: { isRootMutation },
fieldWithHooks,
} = context;
if (!isRootMutation) {
return fields;
}
Expand Down
Expand Up @@ -40,7 +40,10 @@ export default (async function PgMutationUpdateDeletePlugin(
pgOmit: omit,
pgViaTemporaryTable: viaTemporaryTable,
} = build;
const { scope: { isRootMutation }, fieldWithHooks } = context;
const {
scope: { isRootMutation },
fieldWithHooks,
} = context;
const { pluralize, singularize, camelCase } = inflection;
if (!isRootMutation) {
return fields;
Expand Down
Expand Up @@ -3,7 +3,10 @@ import type { Plugin } from "graphile-build";

export default (async function PgNodeAliasPostGraphile(builder) {
builder.hook("GraphQLObjectType", (object, build, context) => {
const { setNodeAlias, inflection: { pluralize } } = build;
const {
setNodeAlias,
inflection: { pluralize },
} = build;
const {
scope: { isPgRowType, isPgCompoundType, pgIntrospection: table },
} = context;
Expand Down
Expand Up @@ -10,7 +10,9 @@ export default (function PgOrderAllColumnsPlugin(builder) {
inflection,
pgOmit: omit,
} = build;
const { scope: { isPgRowSortEnum, pgIntrospection: table } } = context;
const {
scope: { isPgRowSortEnum, pgIntrospection: table },
} = context;
if (!isPgRowSortEnum || !table || table.kind !== "class") {
return values;
}
Expand Down
Expand Up @@ -7,7 +7,9 @@ export default (function PgOrderByPrimaryKeyPlugin(builder) {
extend,
pgIntrospectionResultsByKind: introspectionResultsByKind,
} = build;
const { scope: { isPgRowSortEnum, pgIntrospection: table } } = context;
const {
scope: { isPgRowSortEnum, pgIntrospection: table },
} = context;
if (!isPgRowSortEnum || !table || table.kind !== "class") {
return values;
}
Expand Down
Expand Up @@ -20,7 +20,10 @@ export default (function PgQueryProceduresPlugin(
pgMakeProcField: makeProcField,
pgOmit: omit,
} = build;
const { scope: { isRootQuery }, fieldWithHooks } = context;
const {
scope: { isRootQuery },
fieldWithHooks,
} = context;
if (!isRootQuery) {
return fields;
}
Expand Down
Expand Up @@ -18,7 +18,10 @@ export default (async function PgRowByUniqueConstraint(builder) {
pgQueryFromResolveData: queryFromResolveData,
pgOmit: omit,
} = build;
const { scope: { isRootQuery }, fieldWithHooks } = context;
const {
scope: { isRootQuery },
fieldWithHooks,
} = context;
if (!isRootQuery) {
return fields;
}
Expand Down Expand Up @@ -114,10 +117,9 @@ export default (async function PgRowByUniqueConstraint(builder) {
);
const { text, values } = sql.compile(query);
if (debugSql.enabled) debugSql(text);
const { rows: [row] } = await pgClient.query(
text,
values
);
const {
rows: [row],
} = await pgClient.query(text, values);
return row;
},
};
Expand Down
20 changes: 13 additions & 7 deletions packages/graphile-build-pg/src/plugins/PgRowNode.js
Expand Up @@ -15,7 +15,9 @@ export default (async function PgRowNode(builder) {
pgQueryFromResolveData: queryFromResolveData,
pgOmit: omit,
} = build;
const { scope: { isPgRowType, pgIntrospection: table } } = context;
const {
scope: { isPgRowType, pgIntrospection: table },
} = context;
if (!isPgRowType || !table.namespace || omit(table, "read")) {
return object;
}
Expand Down Expand Up @@ -68,7 +70,9 @@ export default (async function PgRowNode(builder) {
);
const { text, values } = sql.compile(query);
if (debugSql.enabled) debugSql(text);
const { rows: [row] } = await pgClient.query(text, values);
const {
rows: [row],
} = await pgClient.query(text, values);
return row;
}
);
Expand All @@ -90,7 +94,10 @@ export default (async function PgRowNode(builder) {
pgQueryFromResolveData: queryFromResolveData,
pgOmit: omit,
} = build;
const { scope: { isRootQuery }, fieldWithHooks } = context;
const {
scope: { isRootQuery },
fieldWithHooks,
} = context;
if (!isRootQuery || !nodeIdFieldName) {
return fields;
}
Expand Down Expand Up @@ -182,10 +189,9 @@ export default (async function PgRowNode(builder) {
);
const { text, values } = sql.compile(query);
if (debugSql.enabled) debugSql(text);
const { rows: [row] } = await pgClient.query(
text,
values
);
const {
rows: [row],
} = await pgClient.query(text, values);
return row;
} catch (e) {
return null;
Expand Down
4 changes: 3 additions & 1 deletion packages/graphile-build-pg/src/plugins/PgTypesPlugin.js
Expand Up @@ -355,7 +355,9 @@ export default (function PgTypesPlugin(

// pgExtendedTypes might change what types we use for things
const JSONType = pgExtendedTypes
? pgLegacyJsonUuid ? GraphQLJson : GraphQLJSON
? pgLegacyJsonUuid
? GraphQLJson
: GraphQLJSON
: SimpleJSON;
const UUIDType = SimpleUUID; // GraphQLUUID
const DateType = SimpleDate; // GraphQLDate
Expand Down

0 comments on commit a65cdc5

Please sign in to comment.