Skip to content

Commit

Permalink
Update configds for subscription type
Browse files Browse the repository at this point in the history
  • Loading branch information
sgayangi authored and tharindu1st committed Feb 12, 2024
1 parent f5f3bdb commit a37b7b9
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 13 deletions.
28 changes: 21 additions & 7 deletions runtime/config-deployer-service/ballerina/APIClient.bal
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,13 @@ public class APIClient {
}
if endpointToUse != () {
if apkConf.'type == API_TYPE_GRAPHQL {
model:GQLRouteRule gqlRouteRule = {matches: self.retrieveGQLMatches(apkConf, operation, organization)};
return gqlRouteRule;
model:GQLRouteMatch[]|error routeMatches = self.retrieveGQLMatches(apkConf, operation, organization);
if routeMatches is model:GQLRouteMatch[] && routeMatches.length() > 0 {
model:GQLRouteRule gqlRouteRule = {matches: routeMatches};
return gqlRouteRule;
} else {
return e909022("Subscription type currently not supported for GraphQL APIs.", error("Subscription type currently not supported for GraphQL APIs."));
}
} else {
model:HTTPRouteRule httpRouteRule = {matches: self.retrieveHTTPMatches(apkConf, operation, organization), backendRefs: self.retrieveGeneratedBackend(apkConf, endpointToUse, endpointType), filters: self.generateFilters(apiArtifact, apkConf, endpointToUse, operation, endpointType, organization)};
return httpRouteRule;
Expand Down Expand Up @@ -895,19 +900,28 @@ public class APIClient {
return httpRouteMatch;
}

private isolated function retrieveGQLMatches(APKConf apkConf, APKOperations apiOperation, commons:Organization organization) returns model:GQLRouteMatch[] {
private isolated function retrieveGQLMatches(APKConf apkConf, APKOperations apiOperation, commons:Organization organization) returns model:GQLRouteMatch[]|error {
model:GQLRouteMatch[] gqlRouteMatch = [];
model:GQLRouteMatch gqlRoute = self.retrieveGQLRouteMatch(apiOperation);
gqlRouteMatch.push(gqlRoute);
model:GQLRouteMatch|error gqlRoute = self.retrieveGQLRouteMatch(apiOperation);
if gqlRoute is model:GQLRouteMatch {
gqlRouteMatch.push(gqlRoute);
}
return gqlRouteMatch;

}

private isolated function retrieveHttpRouteMatch(APKConf apkConf, APKOperations apiOperation, commons:Organization organization) returns model:HTTPRouteMatch {
return {method: <string>apiOperation.verb, path: {'type: "RegularExpression", value: self.retrievePathPrefix(apkConf.basePath, apkConf.'version, apiOperation.target ?: "/*", organization)}};
}

private isolated function retrieveGQLRouteMatch(APKOperations apiOperation) returns model:GQLRouteMatch {
return {'type: <string>apiOperation.verb, path: <string>apiOperation.target};
private isolated function retrieveGQLRouteMatch(APKOperations apiOperation) returns model:GQLRouteMatch|error {
model:GQLType? routeMatch = model:getGQLRouteMatch(<string>apiOperation.verb);
if routeMatch is model:GQLType {
log:printInfo(routeMatch);
return {'type: routeMatch, path: <string>apiOperation.target};
} else {
return e909052(error("Error occured retrieving GQL route match", message = "Internal Server Error", code = 909000, description = "Internal Server Error", statusCode = 500));
}
}

isolated function retrieveGeneratedSwaggerDefinition(APKConf apkConf, string? definition) returns string|json|commons:APKError|error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,25 @@ public type GQLRouteList record {|
|};

public type GQLRouteMatch record {
string 'type; //TODO: make enum
GQLType 'type;
string path;
};

enum GQLType {
QUERY,
MUTATION
};
public type GQLType "QUERY"|"MUTATION";

public isolated function getGQLRouteMatch(string routeMatch) returns GQLType? {
match routeMatch {
"QUERY" => {
return "QUERY";
}
"MUTATION" => {
return "MUTATION";
} //TODO: add SUBSCRIPTION when support is added
_ => {
return; // Returns `nil` for unmatched cases
}
}
}

public type GQLRouteFilter record {
LocalObjectReference extensionRef?;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
name: "GraphQL API"
basePath: "/graphql"
version: "3.14"
type: "GRAPHQL"
defaultVersion: false
subscriptionValidation: false
endpointConfigurations:
production:
endpoint: "https://run.mocky.io/v3/85516819-1edd-412b-a32b-a9284705a0b4"
operations:
- target: "hero"
verb: "QUERY"
secured: true
scopes: []
- target: "reviews"
verb: "QUERY"
secured: true
scopes: []
- target: "search"
verb: "QUERY"
secured: true
scopes: []
- target: "character"
verb: "QUERY"
secured: true
scopes: []
- target: "droid"
verb: "QUERY"
secured: true
scopes: []
- target: "human"
verb: "QUERY"
secured: true
scopes: []
- target: "allHumans"
verb: "QUERY"
secured: true
scopes: []
- target: "allDroids"
verb: "QUERY"
secured: true
scopes: []
- target: "allCharacters"
verb: "QUERY"
secured: true
scopes: []
- target: "starship"
verb: "QUERY"
secured: true
scopes: []
- target: "createReview"
verb: "MUTATION"
secured: true
scopes: []
- target: "reviewAdded"
verb: "SUBSCRIPTION"
secured: true
scopes: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: "GraphQL API"
basePath: "/graphql"
version: "3.14"
type: "GRAPHQL"
defaultVersion: false
subscriptionValidation: false
endpointConfigurations:
production:
endpoint: "https://run.mocky.io/v3/85516819-1edd-412b-a32b-a9284705a0b4"
operations:
- target: "hero"
verb: "QUERY"
secured: true
scopes: []
- target: "reviews"
verb: "QUERY"
secured: true
scopes: []
- target: "search"
verb: "QUERY"
secured: true
scopes: []
- target: "character"
verb: "QUERY"
secured: true
scopes: []
- target: "droid"
verb: "QUERY"
secured: true
scopes: []
- target: "human"
verb: "QUERY"
secured: true
scopes: []
- target: "allHumans"
verb: "QUERY"
secured: true
scopes: []
- target: "allDroids"
verb: "QUERY"
secured: true
scopes: []
- target: "allCharacters"
verb: "QUERY"
secured: true
scopes: []
- target: "starship"
verb: "QUERY"
secured: true
scopes: []
- target: "createReview"
verb: "MUTATION"
secured: true
scopes: []
17 changes: 16 additions & 1 deletion test/cucumber-tests/src/test/resources/tests/api/GraphQL.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@ Feature: Generating APK conf for GraphQL API
When I use the definition file "artifacts/definitions/graphql_sample_api.graphql" in resources
And generate the APK conf file for a "GRAPHQL" API
Then the response status code should be 200
And the response body should be "artifacts/apk-confs/graphql_conf.apk-conf" in resources

Scenario: Deploying APK conf using a valid GraphQL API definition without a subscription resource
Given The system is ready
And I have a valid subscription
When I use the APK Conf file "artifacts/apk-confs/graphql/graphql_conf_without_sub.apk-conf"
And the definition file "artifacts/definitions/graphql_sample_api.graphql"
And make the API deployment request
Then the response status code should be 200

Scenario: Deploying APK conf using a valid GraphQL API definition containing a subscription resource
Given The system is ready
And I have a valid subscription
When I use the APK Conf file "artifacts/apk-confs/graphql/graphql_conf_with_sub.apk-conf"
And the definition file "artifacts/definitions/graphql_sample_api.graphql"
And make the API deployment request
Then the response status code should be 500

Scenario: Generating APK conf using an invalid GraphQL API definition
Given The system is ready
Expand Down

0 comments on commit a37b7b9

Please sign in to comment.