[SIEM] Fix GraphQL type generation fails to generate types (#47638) (#47748)

This commit is contained in:
patrykkopycinski 2019-10-10 15:29:40 +02:00 committed by GitHub
parent da745fad97
commit 061c0d47c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 7547 additions and 7287 deletions

View file

@ -301,7 +301,7 @@
"@types/getopts": "^2.0.1",
"@types/glob": "^7.1.1",
"@types/globby": "^8.0.0",
"@types/graphql": "^0.13.1",
"@types/graphql": "^0.13.2",
"@types/hapi": "^17.0.18",
"@types/hapi-auth-cookie": "^9.1.0",
"@types/has-ansi": "^3.0.0",

View file

@ -75,7 +75,7 @@ describe('Field Renderers', () => {
});
describe('#autonomousSystemRenderer', () => {
const emptyMock: AutonomousSystem = { organization: {}, number: null };
const emptyMock: AutonomousSystem = { organization: { name: null }, number: null };
const halfEmptyMock: AutonomousSystem = { organization: { name: 'Test Org' }, number: null };
test('it renders correctly against snapshot', () => {

File diff suppressed because it is too large Load diff

View file

@ -14,8 +14,6 @@ const GRAPHQL_GLOBS = [
join('public', 'containers', '**', '*.gql_query.ts{,x}'),
join('common', 'graphql', '**', '*.gql_query.ts{,x}'),
];
const CLIENT_CONFIG_PATH = resolve(__dirname, 'gql_gen_client.json');
const SERVER_CONFIG_PATH = resolve(__dirname, 'gql_gen_server.json');
const OUTPUT_INTROSPECTION_PATH = resolve('public', 'graphql', 'introspection.json');
const OUTPUT_CLIENT_TYPES_PATH = resolve('public', 'graphql', 'types.ts');
const OUTPUT_SERVER_TYPES_PATH = resolve('server', 'graphql', 'types.ts');
@ -24,34 +22,117 @@ const SCHEMA_PATH = resolve(__dirname, 'combined_schema.ts');
async function main() {
await generate(
{
args: GRAPHQL_GLOBS,
config: SERVER_CONFIG_PATH,
out: OUTPUT_INTROSPECTION_PATH,
overwrite: true,
schema: SCHEMA_PATH,
template: 'graphql-codegen-introspection-template',
},
true
);
await generate(
{
args: GRAPHQL_GLOBS,
config: CLIENT_CONFIG_PATH,
out: OUTPUT_CLIENT_TYPES_PATH,
overwrite: true,
schema: SCHEMA_PATH,
template: 'graphql-codegen-typescript-template',
},
true
);
await generate(
{
args: [],
config: SERVER_CONFIG_PATH,
out: OUTPUT_SERVER_TYPES_PATH,
overwrite: true,
schema: SCHEMA_PATH,
template: 'graphql-codegen-typescript-resolvers-template',
generates: {
[OUTPUT_INTROSPECTION_PATH]: {
documents: GRAPHQL_GLOBS,
primitives: {
String: 'string',
Int: 'number',
Float: 'number',
Boolean: 'boolean',
ID: 'string',
},
config: {
namingConvention: {
typeNames: 'change-case#pascalCase',
enumValues: 'keep',
},
contextType: 'SiemContext',
scalars: {
ToStringArray: 'string[] | string',
ToNumberArray: 'number[] | number',
ToDateArray: 'string[] | string',
ToBooleanArray: 'boolean[] | boolean',
Date: 'string',
},
},
plugins: ['introspection'],
},
[OUTPUT_CLIENT_TYPES_PATH]: {
documents: GRAPHQL_GLOBS,
primitives: {
String: 'string',
Int: 'number',
Float: 'number',
Boolean: 'boolean',
ID: 'string',
},
config: {
avoidOptionals: false,
namingConvention: {
typeNames: 'change-case#pascalCase',
enumValues: 'keep',
},
contextType: 'SiemContext',
scalars: {
ToStringArray: 'string[]',
ToNumberArray: 'number[]',
ToDateArray: 'string[]',
ToBooleanArray: 'boolean[]',
Date: 'string',
},
},
plugins: [
{
add: `/* tslint:disable */
/* eslint-disable */
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
`,
},
'typescript-common',
'typescript-server',
'typescript-client',
],
},
[OUTPUT_SERVER_TYPES_PATH]: {
primitives: {
String: 'string',
Int: 'number',
Float: 'number',
Boolean: 'boolean',
ID: 'string',
},
config: {
avoidOptionals: false,
namingConvention: {
typeNames: 'change-case#pascalCase',
enumValues: 'keep',
},
contextType: 'SiemContext',
scalars: {
ToStringArray: 'string[] | string',
ToNumberArray: 'number[] | number',
ToDateArray: 'string[] | string',
ToBooleanArray: 'boolean[] | boolean',
Date: 'string',
},
},
plugins: [
{
add: `
/* tslint:disable */
/* eslint-disable */
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { SiemContext } from '../lib/types';
`,
},
'typescript-common',
'typescript-server',
'typescript-resolvers',
],
},
},
},
true
);

View file

@ -1,28 +0,0 @@
{
"flattenTypes": true,
"generatorConfig": {
"prepend": [
"/* eslint-disable */",
"/*",
" * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one",
" * or more contributor license agreements. Licensed under the Elastic License;",
" * you may not use this file except in compliance with the Elastic License.",
" */",
""
],
"scalars": {
"ToStringArray": "string[]",
"ToNumberArray": "number[]",
"ToDateArray": "string[]",
"ToBooleanArray": "boolean[]",
"Date": "string"
}
},
"primitives": {
"String": "string",
"Int": "number",
"Float": "number",
"Boolean": "boolean",
"ID": "string"
}
}

View file

@ -1,30 +0,0 @@
{
"flattenTypes": true,
"generatorConfig": {
"contextType": "SiemContext",
"prepend": [
"/* eslint-disable */",
"/*",
" * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one",
" * or more contributor license agreements. Licensed under the Elastic License;",
" * you may not use this file except in compliance with the Elastic License.",
" */",
"",
"import { SiemContext } from '../lib/types';"
],
"scalars": {
"ToStringArray": "string[] | string",
"ToNumberArray": "number[] | number",
"ToDateArray": "string[] | string",
"ToBooleanArray": "boolean[] | boolean",
"Date": "string"
}
},
"primitives": {
"String": "string",
"Int": "number",
"Float": "number",
"Boolean": "boolean",
"ID": "string"
}
}

File diff suppressed because it is too large Load diff

View file

@ -5,8 +5,15 @@
*/
import * as runtimeTypes from 'io-ts';
import { GraphQLResolveInfo } from 'graphql';
import { Resolver } from '../graphql/types';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Resolver<Result, Parent = never, TContext = never, Args = any> = (
parent: Parent,
args: Args,
context: TContext,
info: GraphQLResolveInfo
) => Promise<Result> | Result;
type ResolverResult<R> = R | Promise<R>;

View file

@ -61,7 +61,7 @@
"@types/getos": "^3.0.0",
"@types/git-url-parse": "^9.0.0",
"@types/glob": "^7.1.1",
"@types/graphql": "^0.13.1",
"@types/graphql": "^0.13.2",
"@types/gulp": "^4.0.6",
"@types/hapi__wreck": "^15.0.1",
"@types/history": "^4.7.3",
@ -135,9 +135,12 @@
"fancy-log": "^1.3.2",
"fetch-mock": "^7.3.9",
"graphql-code-generator": "^0.18.2",
"graphql-codegen-introspection-template": "^0.13.0",
"graphql-codegen-typescript-resolvers-template": "^0.13.0",
"graphql-codegen-typescript-template": "^0.13.0",
"graphql-codegen-add": "^0.18.2",
"graphql-codegen-introspection": "^0.18.2",
"graphql-codegen-typescript-resolvers": "^0.18.2",
"graphql-codegen-typescript-common": "^0.18.2",
"graphql-codegen-typescript-server": "^0.18.2",
"graphql-codegen-typescript-client": "^0.18.2",
"gulp": "4.0.2",
"gulp-mocha": "^7.0.2",
"gulp-multi-process": "1.3.1",

View file

@ -103,7 +103,7 @@ export default function({ getService }: FtrProviderContext) {
});
it('Make sure that we get Host Overview data', () => {
const expectedHost: GetHostOverviewQuery.HostOverview = {
const expectedHost: Omit<GetHostOverviewQuery.HostOverview, 'inspect'> = {
_id: 'zeek-sensor-san-francisco',
host: {
architecture: ['x86_64'],

View file

@ -3351,7 +3351,7 @@
"@types/glob" "*"
fast-glob "^2.0.2"
"@types/graphql@^0.13.1":
"@types/graphql@^0.13.2":
version "0.13.4"
resolved "https://registry.yarnpkg.com/@types/graphql/-/graphql-0.13.4.tgz#55ae9c29f0fd6b85ee536f5c72b4769d5c5e06b1"
integrity sha512-B4yel4ro2nTb3v0pYO8vO6SjgvFJSrwUY+IO6TUSLdOSB+gQFslylrhRCHxvXMIhxB71mv5PEE9dAX+24S8sew==
@ -13845,6 +13845,13 @@ graphql-code-generator@^0.18.2:
request "2.88.0"
valid-url "1.0.9"
graphql-codegen-add@^0.18.2:
version "0.18.2"
resolved "https://registry.yarnpkg.com/graphql-codegen-add/-/graphql-codegen-add-0.18.2.tgz#27625f6b6bcfe29076b5f8b02496425eeb360b46"
integrity sha512-X8i3WEjfI2YYS6giE3BZ0LlOlTnae2btuyjU1TAN7Cec+dOI5XzRz25cPRi6D1Y0++j2h480e60tgXwMORW9pA==
dependencies:
graphql-codegen-core "0.18.2"
graphql-codegen-core@0.18.2:
version "0.18.2"
resolved "https://registry.yarnpkg.com/graphql-codegen-core/-/graphql-codegen-core-0.18.2.tgz#205b25d2bdb20a35b986495b60d219a8d02ef266"
@ -13859,22 +13866,52 @@ graphql-codegen-core@0.18.2:
ts-log "2.1.4"
winston "3.2.1"
graphql-codegen-introspection-template@^0.13.0:
version "0.13.0"
resolved "https://registry.yarnpkg.com/graphql-codegen-introspection-template/-/graphql-codegen-introspection-template-0.13.0.tgz#7bd4ae777f1a8d078a09974866fe27a0d928a040"
integrity sha512-qYzupnNEr6EI3r0sHhEl0wvlgTpuzWx4MkVCY5rgeSweLOLKlmrwCySMZ8lxzFR9D1Y5alvW3C8LrWHPTuWIug==
graphql-codegen-introspection@^0.18.2:
version "0.18.2"
resolved "https://registry.yarnpkg.com/graphql-codegen-introspection/-/graphql-codegen-introspection-0.18.2.tgz#1e749e342aebe219271dcf4c5c56357ad300921a"
integrity sha512-L71rDI9gFQdcGNHsOnlW8nOtUXsZCFnXvC+faEwNse4P/OGrRm4jLQU/6/EUk92okFCbLytKWNcq1uxD8fiY1Q==
graphql-codegen-typescript-resolvers-template@^0.13.0:
version "0.13.0"
resolved "https://registry.yarnpkg.com/graphql-codegen-typescript-resolvers-template/-/graphql-codegen-typescript-resolvers-template-0.13.0.tgz#fd525e5199d15714f7cb079b7b7b44dd5ba3a531"
integrity sha512-guaQ+xbg+18TqiBSXWpgKf88tvoPaOtLkExhW5eMQnfBJ7PpX3AcOjExb+AKsQAH9DK6zL4n+txU7WeUfzGDbA==
graphql-codegen-plugin-helpers@0.18.2:
version "0.18.2"
resolved "https://registry.yarnpkg.com/graphql-codegen-plugin-helpers/-/graphql-codegen-plugin-helpers-0.18.2.tgz#ce03d02ced0bc28ef2f61e0a5205d85ee7e9ccdb"
integrity sha512-WZahfp95RdePwwPWxnxAHgfkXXEQXNrgX9sGrB//uGfj8lygcf7m/rNZQ4iooUzoqBEkTtJpi7bezWCieNcq2A==
dependencies:
graphql-codegen-typescript-template "0.13.0"
graphql-codegen-core "0.18.2"
import-from "2.1.0"
graphql-codegen-typescript-template@0.13.0, graphql-codegen-typescript-template@^0.13.0:
version "0.13.0"
resolved "https://registry.yarnpkg.com/graphql-codegen-typescript-template/-/graphql-codegen-typescript-template-0.13.0.tgz#41398687cbf279f1d97d8cfb8aa7c412bf0e7192"
integrity sha512-EYLd4v8toD+dpWHJsJliViaE52novhF9zbayFmY8IgLeHmYPVk2TfyS6CVvHmCoa0HTxOawvTY8a7UIgtnpw2w==
graphql-codegen-typescript-client@^0.18.2:
version "0.18.2"
resolved "https://registry.yarnpkg.com/graphql-codegen-typescript-client/-/graphql-codegen-typescript-client-0.18.2.tgz#5478f8af83fac8063362fe2905dac20fe02d5548"
integrity sha512-HffKYPrT5jGIRTiWCTst/X3EBpuOHsheI5tKUEf9NfrR8ySWs6PfqZO5fKCFWZOqC9xn7Y75jFXaeH8tgV5y1g==
dependencies:
graphql-codegen-core "0.18.2"
graphql-codegen-plugin-helpers "0.18.2"
graphql-codegen-typescript-common "0.18.2"
graphql-codegen-typescript-common@0.18.2, graphql-codegen-typescript-common@^0.18.2:
version "0.18.2"
resolved "https://registry.yarnpkg.com/graphql-codegen-typescript-common/-/graphql-codegen-typescript-common-0.18.2.tgz#1ccbb3bfa1aeb8664127f881db27c658636465da"
integrity sha512-uGGHd/vgwMlnCNOMQkvMxW8Xz0fqPGjPHROsniRNP1ragsa6KfFBrGu9toHgxv8m3MzC6ZPeoUa3wtwtS9oVnA==
dependencies:
change-case "3.1.0"
common-tags "1.8.0"
graphql-codegen-core "0.18.2"
graphql-codegen-plugin-helpers "0.18.2"
graphql-codegen-typescript-resolvers@^0.18.2:
version "0.18.2"
resolved "https://registry.yarnpkg.com/graphql-codegen-typescript-resolvers/-/graphql-codegen-typescript-resolvers-0.18.2.tgz#fa44b2668285184d2976116c2982c17bc6866a23"
integrity sha512-BlS286ap2hsOjx2a7H6WKcwxfQtjRay9d+P/0u4t6zUkjpFSpHWWYgymVopfckrjHCo/8g+THPFCmUgFg34vKQ==
dependencies:
graphql-codegen-plugin-helpers "0.18.2"
graphql-codegen-typescript-common "0.18.2"
graphql-codegen-typescript-server@^0.18.2:
version "0.18.2"
resolved "https://registry.yarnpkg.com/graphql-codegen-typescript-server/-/graphql-codegen-typescript-server-0.18.2.tgz#2e11607512bdf77b152c554afc18f5210c1785ba"
integrity sha512-1marSv3TCry6IsQd+Hdarq/AhDpgJ3Yg+e9Or3Urv7Fkw4YbhtyGp6AkpBK+DMKlyKFPjpLnmjAaHS3hjrCp3Q==
dependencies:
graphql-codegen-typescript-common "0.18.2"
graphql-config@2.2.1:
version "2.2.1"
@ -13926,16 +13963,11 @@ graphql-tag-pluck@0.6.0:
source-map-support "^0.5.9"
typescript "^3.2.2"
graphql-tag@2.10.1:
graphql-tag@2.10.1, graphql-tag@^2.9.2:
version "2.10.1"
resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-2.10.1.tgz#10aa41f1cd8fae5373eaf11f1f67260a3cad5e02"
integrity sha512-jApXqWBzNXQ8jYa/HLkZJaVw9jgwNqZkywa2zfFn16Iv1Zb7ELNHkJaXHR7Quvd5SIGsy6Ny7SUKATgnu05uEg==
graphql-tag@^2.9.2:
version "2.10.0"
resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-2.10.0.tgz#87da024be863e357551b2b8700e496ee2d4353ae"
integrity sha512-9FD6cw976TLLf9WYIUPCaaTpniawIjHWZSwIRZSjrfufJamcXbVVYfN2TWvJYbw0Xf2JjYbl1/f2+wDnBVw3/w==
graphql-toolkit@0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/graphql-toolkit/-/graphql-toolkit-0.2.0.tgz#91364b69911d51bc915269a37963f4ea2d5f335c"
@ -15112,7 +15144,7 @@ import-fresh@^3.0.0:
parent-module "^1.0.0"
resolve-from "^4.0.0"
import-from@^2.1.0:
import-from@2.1.0, import-from@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/import-from/-/import-from-2.1.0.tgz#335db7f2a7affd53aaa471d4b8021dee36b7f3b1"
integrity sha1-M1238qev/VOqpHHUuAId7ja387E=