Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency Upgrades + Breaking Peer Dependency change for faker #40

Merged
merged 16 commits into from
Sep 9, 2024
Merged
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 18.15.0
nodejs 22.7.0
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ and this project adheres to

## [Unreleased]

## [v2.0.0] - 2024-09-09

### Chore

- Updated many dependencies of this library. See the package.json diff for
details.

### Breaking

- `@faker-js/faker` is now a peer dependency and is required to be installed by
consuming projects if that functionality is used.

## [v1.3.1] - 2024-02-08

### Fixed
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ for installation via [yarn][yarn]
yarn add --dev @wayfair/gqmock
```

NOTE: If you plan on using the `fakerConfig` functionality of this library, you
must also install the `@faker-js/faker` dev dependency.

## Library API

### `GraphqlMockingService`
Expand Down
41 changes: 22 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wayfair/gqmock",
"version": "1.3.1",
"version": "2.0.0",
"description": "GQMock - GraphQL Mocking Service",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -43,36 +43,39 @@
],
"homepage": "https://github.com/wayfair-incubator/gqmock#readme",
"dependencies": {
"@apollo/server": "^4.1.1",
"@apollo/subgraph": "^2.1.3",
"@babel/runtime": "^7.18.9",
"@faker-js/faker": "^7.6.0",
"@graphql-tools/mock": "^8.7.12",
"chalk": "4.1.2",
"@apollo/server": "^4.11.0",
"@apollo/subgraph": "^2.9.0",
"@babel/runtime": "^7.25.6",
"@graphql-tools/mock": "^9.0.4",
"chalk": "^5.3.0",
"cors": "^2.8.5",
"escape-string-regexp": "^4.0.0",
"express": "^4.18.1",
"graphql": "^16.6.0",
"joi": "^17.6.0",
"express": "^4.19.2",
"graphql": "^16.9.0",
"joi": "^17.13.3",
"lodash": "^4.17.21",
"node-fetch": "^2.6.7",
"uuid": "^8.3.2"
"uuid": "^10.0.0"
},
"devDependencies": {
"@babel/core": "^7.18.13",
"@babel/preset-env": "^7.18.10",
"@babel/preset-typescript": "^7.18.6",
"@types/cors": "^2.8.15",
"@types/jest": "^29.1.2",
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.4",
"@babel/preset-typescript": "^7.24.7",
"@faker-js/faker": "^9.0.0",
"@types/cors": "^2.8.17",
"@types/jest": "^29.5.12",
"@typescript-eslint/eslint-plugin": "^5.35.1",
"@typescript-eslint/parser": "^5.35.1",
"doctoc": "^2.2.1",
"eslint": "^8.22.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jsdoc": "^39.3.6",
"eslint-plugin-jsdoc": "^50.2.2",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.0.0",
"jest": "^29.7.0",
"prettier": "^2.7.1",
"typescript": "^4"
"typescript": "^5.5.4"
},
"peerDependencies": {
"@faker-js/faker": "^7 || ^8 || ^9"
}
}
2 changes: 0 additions & 2 deletions src/ApolloServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
});
}

private createCustomMocks(fakerConfig: Record<string, any>) {

Check warning on line 74 in src/ApolloServerManager.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
const mocks = {};

Object.entries(fakerConfig).forEach(([key, value]) => {
Expand All @@ -86,9 +86,9 @@
key,
value,
}: {
mocks: Record<string, any>;

Check warning on line 89 in src/ApolloServerManager.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
key: string;
value: Record<string, any>;

Check warning on line 91 in src/ApolloServerManager.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
}) {
if (
// detect a faker method definition:
Expand Down Expand Up @@ -129,7 +129,7 @@

private getFakerMethod(
fakerKeys: string[]
): (...args: any[]) => any | null | undefined {

Check warning on line 132 in src/ApolloServerManager.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 132 in src/ApolloServerManager.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
let fakerMethod = faker;

while (fakerKeys.length) {
Expand Down Expand Up @@ -372,12 +372,10 @@
return (
unionTypeDefinitions
.filter((unionTypeDefinition) =>
// @ts-expect-error We know this is a union type definition
unionTypeDefinition?.types?.find(
(typeDefinition) => typeDefinition.name.value === typeName
)
)
// @ts-expect-error We know this is a union type definition
.map((unionTypeDefinition) => unionTypeDefinition.name.value) || []
);
}
Expand Down
21 changes: 12 additions & 9 deletions src/__tests__/GraphqlMockingService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,29 +986,29 @@ query itemsQuery { officeItems: items(type: "office") { ...commonItems3 } homeIt
const fakerConfig = {
Product: {
id: {
method: 'datatype.string',
method: 'string.alpha',
},
name: {
method: 'commerce.product',
},
},
Dimensions: {
length: {
method: 'random.numeric',
args: 2,
method: 'number.int',
args: {min: 10, max: 99},
},
width: {
method: 'random.numeric',
args: [2],
method: 'number.int',
args: {min: 10, max: 99},
},
height: {
method: 'random.numeric',
args: 3,
method: 'number.int',
args: {min: 100, max: 999},
},
},
ProductVariant: {
name: {
method: 'random.words',
method: 'word.words',
args: 3,
},
},
Expand All @@ -1019,7 +1019,7 @@ query itemsQuery { officeItems: items(type: "office") { ...commonItems3 } homeIt
const fakerWithScalars = {
...fakerConfig,
DateTime: {
method: 'datatype.datetime',
method: 'date.anytime',
},
};
await mockingService.registerSchema(schema, {
Expand Down Expand Up @@ -1091,6 +1091,9 @@ query itemsQuery { officeItems: items(type: "office") { ...commonItems3 } homeIt
name: 'Hello World',
})
);
operationResult.data[operationName].variants.forEach((variant) => {
expect(variant.name.split(' ').length).toEqual(3);
});
});
});

Expand Down
Loading
Loading