-
Notifications
You must be signed in to change notification settings - Fork 78
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
Feat: API call to query Enum values #1435
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ec44278
enums queries and example with maintenance
4b0790d
shared enumFetcher in services
c22e481
all enums automatically have queries
fbcb947
make ruff happy
f51ae8f
one query to rule them all
ac03c01
multiple enums in one request
6937f97
PR changes
1c14949
comments
b4e0336
Merge branch 'mda-main' into query-enums
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from dataall.base.api import gql | ||
from dataall.base.api.resolvers import enum_resolver | ||
from dataall.base.api.types import EnumResult | ||
|
||
enumsQuery = gql.QueryField( | ||
name='queryEnums', | ||
args=[gql.Argument(name='enums_names', type=gql.ArrayType(gql.String))], | ||
type=gql.ArrayType(EnumResult), | ||
resolver=enum_resolver, | ||
test_scope='Enums', | ||
) |
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,14 @@ | ||
from dataall.base.api.constants import GraphQLEnumMapper | ||
|
||
|
||
def enum_resolver(context, source, enums_names): | ||
result = [] | ||
for enum_class in GraphQLEnumMapper.__subclasses__(): | ||
if enum_class.__name__ in enums_names: | ||
result.append( | ||
{ | ||
'name': enum_class.__name__, | ||
'items': [{'name': item.name, 'value': str(item.value)} for item in enum_class], | ||
} | ||
) | ||
return result |
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 @@ | ||
from dataall.base.api import gql | ||
|
||
EnumItem = gql.ObjectType( | ||
name='EnumItem', | ||
fields=[ | ||
gql.Field(name='name', type=gql.String), | ||
gql.Field(name='value', type=gql.String), | ||
], | ||
) | ||
|
||
EnumResult = gql.ObjectType( | ||
name='EnumResult', | ||
fields=[ | ||
gql.Field(name='name', type=gql.String), | ||
gql.Field(name='items', type=gql.ArrayType(EnumItem)), | ||
], | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { gql } from 'apollo-boost'; | ||
|
||
const getEnumByName = ({ enum_names }) => ({ | ||
variables: { | ||
enum_names: enum_names | ||
}, | ||
query: gql` | ||
query queryEnums($enum_names: [String]) { | ||
queryEnums(enums_names: $enum_names) { | ||
name | ||
items { | ||
name | ||
value | ||
} | ||
} | ||
} | ||
` | ||
}); | ||
|
||
/// function to fetch multiple enums | ||
/// output -- dictionary | ||
// { | ||
// 'enumName': [{name: '...', value: '..'}] | ||
// } | ||
export const fetchEnums = async (client, enum_names) => { | ||
const response = await client.query( | ||
getEnumByName({ enum_names: enum_names }) | ||
); | ||
if (!response.errors && response.data.queryEnums != null) { | ||
return Object.assign( | ||
{}, | ||
...response.data.queryEnums.map((x) => ({ [x.name]: x.items })) | ||
); | ||
} | ||
return {}; | ||
}; |
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 @@ | ||
export * from './getEnumByName'; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd keep only this method and drop the fetchOneEnum and if I want to query one I'd pass
fetchEnums(..., ['EnumName'])