-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Translations for Region Map (#23875) add translations for region_map plugin * Translations for Table Vis plugin (#23679) add translations for table vis plugin * add a simple example/flow to see what need to be done to query with graphql * work review * simple test for source schema * fix some reviewing and add resolver test code for source * review by Andrew G
- Loading branch information
1 parent
a022bcd
commit a69f4d4
Showing
15 changed files
with
374 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
x-pack/plugins/secops/public/containers/who_am_i/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 { getOr } from 'lodash/fp'; | ||
import React from 'react'; | ||
import { Query } from 'react-apollo'; | ||
|
||
import { WhoAmIQuery } from '../../../common/graphql/types'; | ||
|
||
import { whoAmIQuery } from './who_am_i.gql_query'; | ||
|
||
interface WhoAmIArgs { | ||
appName: string; | ||
} | ||
|
||
interface WHoAmIProps { | ||
children: (args: WhoAmIArgs) => React.ReactNode; | ||
sourceId: string; | ||
} | ||
|
||
export const WhoAmI = ({ children, sourceId }: WHoAmIProps) => ( | ||
<Query<WhoAmIQuery.Query, WhoAmIQuery.Variables> | ||
query={whoAmIQuery} | ||
fetchPolicy="no-cache" | ||
notifyOnNetworkStatusChange | ||
variables={{ sourceId }} | ||
> | ||
{({ data }) => | ||
children({ | ||
appName: getOr('Who am I ?', 'source.whoAmI.appName', data), | ||
}) | ||
} | ||
</Query> | ||
); |
17 changes: 17 additions & 0 deletions
17
x-pack/plugins/secops/public/containers/who_am_i/who_am_i.gql_query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* 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 gql from 'graphql-tag'; | ||
|
||
export const whoAmIQuery = gql` | ||
query WhoAmIQuery($sourceId: ID!) { | ||
source(id: $sourceId) { | ||
whoAmI { | ||
appName | ||
} | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
x-pack/plugins/secops/server/graphql/sources/resolvers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 { GraphQLResolveInfo } from 'graphql'; | ||
import { Sources, SourcesAdapter } from '../../lib/sources'; | ||
import { createSourcesResolvers, SourcesResolversDeps } from './resolvers'; | ||
import { mockSourceData } from './source.mock'; | ||
|
||
const mockGetAll = jest.fn(); | ||
mockGetAll.mockResolvedValue({ | ||
default: { | ||
...mockSourceData.configuration, | ||
}, | ||
}); | ||
const mockSourcesAdapter: SourcesAdapter = { | ||
getAll: mockGetAll, | ||
}; | ||
const mockLibs: SourcesResolversDeps = { | ||
sources: new Sources(mockSourcesAdapter), | ||
}; | ||
const context: any = { | ||
req: { | ||
params: {}, | ||
query: {}, | ||
payload: { | ||
operationName: 'test', | ||
}, | ||
}, | ||
}; | ||
|
||
describe('Test Source Resolvers', () => { | ||
test(`Make sure that getCongiguration have been called`, async () => { | ||
const data = await createSourcesResolvers(mockLibs).Query.source( | ||
null, | ||
{ id: 'default' }, | ||
context, | ||
{} as GraphQLResolveInfo | ||
); | ||
expect(mockSourcesAdapter.getAll).toHaveBeenCalled(); | ||
expect(data).toEqual(mockSourceData); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
x-pack/plugins/secops/server/graphql/sources/schema.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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 { graphql } from 'graphql'; | ||
import { addMockFunctionsToSchema, makeExecutableSchema } from 'graphql-tools'; | ||
|
||
import { rootSchema } from '../../../common/graphql/root/schema.gql'; | ||
import { Logger } from '../../utils/logger'; | ||
import { sourcesSchema } from './schema.gql'; | ||
import { getSourceQueryMock, mockSourceData } from './source.mock'; | ||
|
||
const testCaseSource = { | ||
id: 'Test case to query basic information from source', | ||
query: ` | ||
query SourceQuery($sourceId: ID!) { | ||
source(id: $sourceId) { | ||
id | ||
configuration { | ||
fields { | ||
host | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
variables: { sourceId: 'default' }, | ||
context: { | ||
req: { | ||
payload: { | ||
operationName: 'test', | ||
}, | ||
}, | ||
}, | ||
expected: { | ||
data: { | ||
source: { | ||
...mockSourceData, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
describe('Test Source Schema', () => { | ||
// Array of case types | ||
const cases = [testCaseSource]; | ||
const typeDefs = [rootSchema, sourcesSchema]; | ||
const mockSchema = makeExecutableSchema({ typeDefs }); | ||
|
||
// Here we specify the return payloads of mocked types | ||
const logger: Logger = { | ||
debug: jest.fn(), | ||
info: jest.fn(), | ||
warn: jest.fn(), | ||
error: jest.fn(), | ||
}; | ||
const mocks = { | ||
Query: () => ({ | ||
...getSourceQueryMock(logger), | ||
}), | ||
}; | ||
|
||
addMockFunctionsToSchema({ | ||
schema: mockSchema, | ||
mocks, | ||
}); | ||
|
||
cases.forEach(obj => { | ||
const { id, query, variables, context, expected } = obj; | ||
|
||
test(`${id}`, async () => { | ||
const result = await graphql(mockSchema, query, null, context, variables); | ||
return await expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.