Skip to content

Commit

Permalink
feat: add CORS policy to graphql template
Browse files Browse the repository at this point in the history
  • Loading branch information
micovery committed May 8, 2024
1 parent 81f174f commit 9628c3e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/render/using-graphql-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ apigee-go-gen render apiproxy \
--template ./examples/templates/graphql/apiproxy.yaml \
--set-graphql schema=./examples/graphql/resorts.graphql \
--set-string "api_name=resorts-api" \
--set-string "base_path=/graphql" \
--set-string "base_path=/resorts/graphql" \
--set-string "target_url=https://example.com/graphql" \
--include ./examples/templates/graphql/*.tmpl \
--output ./out/apiproxies/resorts.zip
Expand All @@ -54,7 +54,7 @@ apigee-go-gen render apiproxy \
--template ./examples/templates/graphql/apiproxy.yaml \
--set-graphql schema=./examples/graphql/resorts.graphql \
--set-string "api_name=resorts-api" \
--set-string "base_path=/graphql" \
--set-string "base_path=/resorts/graphql" \
--set-string "target_url=https://example.com/graphql" \
--include ./examples/templates/graphql/*.tmpl \
--output ./out/apiproxies/resorts.zip
Expand Down
8 changes: 5 additions & 3 deletions examples/templates/graphql/apiproxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ ProxyEndpoints:
.name: PreFlow
Request:
- Step:
Name: GraphQL-Verify
Name: CORS-Allow
- Step:
Name: GQL-Verify
Flows:
- Flow:
.name: graphQLPost
Condition: (proxy.pathsuffix MatchesPath "{{ $.Values.base_path }}") and (request.verb = "POST")
Condition: (proxy.pathsuffix MatchesPath "/graphql") and (request.verb = "POST")
- Flow:
.name: graphQLGet
Condition: (proxy.pathsuffix MatchesPath "{{ $.Values.base_path }}") and (request.verb = "GET")
Condition: (proxy.pathsuffix MatchesPath "/graphql") and (request.verb = "GET")
- Flow:
.name: CatchAll
Request:
Expand Down
17 changes: 15 additions & 2 deletions examples/templates/graphql/policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.
---
- CORS:
.continueOnError: false
.enabled: true
.name: CORS-Allow
DisplayName: CORS-Allow
AllowOrigins: '{request.header.origin}'
AllowMethods: GET, PUT, POST, DELETE, OPTIONS
AllowHeaders: '*'
ExposeHeaders: '*'
MaxAge: 3628800
AllowCredentials: true
GeneratePreflightResponse: true
IgnoreUnresolvedVariables: true
- GraphQL:
.name: GQL-Verify
Source: request
OperationType: query_mutation
MaxDepth: 4
MaxCount: 4
MaxDepth: 10
MaxCount: 10
Action: parse_verify
ResourceURL: graphql://schema.graphql
- RaiseFault:
Expand Down

0 comments on commit 9628c3e

Please sign in to comment.