-
Notifications
You must be signed in to change notification settings - Fork 289
Add Graphql support for stored procedure #979
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
Merged
abhishekkumams
merged 54 commits into
main
from
dev/abhishekkuma/add-graphql-support-for-stored-procedure
Nov 29, 2022
Merged
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
411f5c4
adding support for graphQL Queries
abhishekkumams c374f1b
resolving merge conflicts
abhishekkumams 7b43e47
fixing doc
abhishekkumams 5774c0f
fix formatting
abhishekkumams 58cca3e
adding support for mutation
abhishekkumams f7015ce
fixing mutation queries
abhishekkumams c6cfd93
fixing temp changes
abhishekkumams 3bb2670
cleaning code
abhishekkumams 270a599
fix formatting
abhishekkumams 15781bd
removing redundant
abhishekkumams eb34b0d
adding tests
abhishekkumams 74decf4
fix argument type for graphQL
abhishekkumams 615bb74
fixing field level authorization
abhishekkumams 61eff13
fixing build
abhishekkumams a36f246
added new tests
abhishekkumams ee08d62
fix formatting
abhishekkumams c151678
fix commands file
abhishekkumams bd6eab2
resolve conflicts
abhishekkumams f841fdc
fixing tests
abhishekkumams d5016da
fixing tests
abhishekkumams 1b45a78
using GetDefinedSingularName for stored-procedure graphQL
abhishekkumams bf62575
fix formatting
abhishekkumams 2017c74
fixing tests
abhishekkumams 07e47bc
fixing tests
abhishekkumams ae84c77
fixing pagination tests
abhishekkumams 42d6058
Merge branch 'main' into dev/abhishekkuma/add-graphql-support-for-sto…
abhishekkumams 1171786
fixing test
abhishekkumams 43c07c2
Merge branch 'dev/abhishekkuma/add-graphql-support-for-stored-procedu…
abhishekkumams 293983b
fix formatting
abhishekkumams 9c7f13d
updating MsSQL commands file
abhishekkumams a9c2536
fixing rest tests
abhishekkumams 091bfbf
fixing tests
abhishekkumams a8fc53a
adding new tests
abhishekkumams 3c35ae7
fix formatting
abhishekkumams d6af949
fixing test
abhishekkumams 56257fe
Merge branch 'main' into dev/abhishekkuma/add-graphql-support-for-sto…
abhishekkumams 58ade56
fix formatting
abhishekkumams 8f7b19a
Merge branch 'dev/abhishekkuma/add-graphql-support-for-stored-procedu…
abhishekkumams 53a0ebb
reomoving comented code
abhishekkumams 597c3ca
fix formatting
abhishekkumams eba1b6a
Merge branch 'main' into dev/abhishekkuma/add-graphql-support-for-sto…
abhishekkumams 18d0a09
Merge branch 'main' into dev/abhishekkuma/add-graphql-support-for-sto…
abhishekkumams 3e3c744
fixed action validation for stored procedure
abhishekkumams e37dfe0
Merge branch 'dev/abhishekkuma/add-graphql-support-for-stored-procedu…
abhishekkumams c364c36
updating docs
abhishekkumams 44dabe8
updating stored-procedures
abhishekkumams 62c80c0
fixing tests
abhishekkumams 6dbf262
resolving merge conflicts
abhishekkumams e3b3e10
Merge branch 'main' into dev/abhishekkuma/add-graphql-support-for-sto…
abhishekkumams fbb329b
fix formatting
abhishekkumams 73d3dc6
Merge branch 'dev/abhishekkuma/add-graphql-support-for-stored-procedu…
abhishekkumams eca1846
resolving comments
abhishekkumams 0a5e200
moved GetSourcedefinition to DatabaseObject class
abhishekkumams 961885f
resolved nits
abhishekkumams 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
97 changes: 97 additions & 0 deletions
97
src/Service.GraphQLBuilder/GraphQLStoredProcedureBuilder.cs
This file contains hidden or 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,97 @@ | ||
| using System.Text.Json; | ||
| using Azure.DataApiBuilder.Config; | ||
| using HotChocolate.Language; | ||
| using HotChocolate.Types; | ||
| using static Azure.DataApiBuilder.Service.GraphQLBuilder.GraphQLUtils; | ||
|
|
||
| namespace Azure.DataApiBuilder.Service.GraphQLBuilder | ||
| { | ||
| public static class GraphQLStoredProcedureBuilder | ||
| { | ||
| /// <summary> | ||
| /// Helper function to create StoredProcedure Schema for GraphQL. | ||
| /// It uses the parameters to build the arguments and returns a list | ||
| /// of the StoredProcedure GraphQL object. | ||
| /// </summary> | ||
| public static FieldDefinitionNode GenerateStoredProcedureSchema( | ||
| NameNode name, | ||
| Entity entity, | ||
| IEnumerable<string>? rolesAllowed = null) | ||
| { | ||
| List<InputValueDefinitionNode> inputValues = new(); | ||
| List<DirectiveNode> fieldDefinitionNodeDirectives = new(); | ||
|
|
||
| if (entity.Parameters is not null) | ||
abhishekkumams marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
abhishekkumams marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| foreach (string param in entity.Parameters.Keys) | ||
| { | ||
| Tuple<string, IValueNode> defaultGraphQLValue = GetGraphQLTypeAndNodeTypeFromStringValue(entity.Parameters[param].ToString()!); | ||
| inputValues.Add( | ||
| new( | ||
| location: null, | ||
| new(param), | ||
| new StringValueNode($"parameters for {name.Value} stored-procedure"), | ||
abhishekkumams marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| new NamedTypeNode(defaultGraphQLValue.Item1), | ||
| defaultValue: defaultGraphQLValue.Item2, | ||
| new List<DirectiveNode>()) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| if (CreateAuthorizationDirectiveIfNecessary( | ||
| rolesAllowed, | ||
| out DirectiveNode? authorizeDirective)) | ||
| { | ||
| fieldDefinitionNodeDirectives.Add(authorizeDirective!); | ||
| } | ||
|
|
||
| return new( | ||
| location: null, | ||
| new NameNode(name.Value), | ||
| new StringValueNode($"Execute Stored-Procedure {name.Value} and get results from the database"), | ||
| inputValues, | ||
| new NonNullTypeNode(new ListTypeNode(new NonNullTypeNode(new NamedTypeNode(name)))), | ||
| fieldDefinitionNodeDirectives | ||
| ); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Takes the result from DB as JsonDocument and formats it in a way that can be filtered by column | ||
| /// name. It parses the Json document into a list of Dictionary with key as result_column_name | ||
| /// with it's corresponding value. | ||
| /// returns an empty list in case of no result | ||
| /// or stored-procedure is trying to read from DB without READ permission. | ||
| /// </summary> | ||
| public static List<JsonDocument> FormatStoredProcedureResultAsJsonList(bool IsReadAllowed, JsonDocument jsonDocument) | ||
| { | ||
| if (jsonDocument is null || !IsReadAllowed) | ||
abhishekkumams marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return new List<JsonDocument>(); | ||
| } | ||
|
|
||
| List<JsonDocument> resultJson = new(); | ||
| List<Dictionary<string, object>> resultList = JsonSerializer.Deserialize<List<Dictionary<string, object>>>(jsonDocument.RootElement.ToString())!; | ||
| foreach (Dictionary<string, object> result in resultList) | ||
| { | ||
| resultJson.Add(JsonDocument.Parse(JsonSerializer.Serialize(result))); | ||
| } | ||
|
|
||
| return resultJson; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Helper method to create a default result field for stored-procedure which does not | ||
| /// return any row. | ||
| /// </summary> | ||
| public static FieldDefinitionNode GetDefaultResultFieldForStoredProcedure() | ||
| { | ||
| return new( | ||
| location: null, | ||
| new("result"), | ||
| description: new StringValueNode("Contains output of stored-procedure execution"), | ||
| new List<InputValueDefinitionNode>(), | ||
| new StringType().ToTypeNode(), | ||
| new List<DirectiveNode>()); | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.