graphql-engine/server/tests-py/queries/endpoints/setup.yaml
Lyndon Maydwell 08da0c63b6 REST Endpoints - Prohibit Invalid slashes, duplicate variables, non-singular query definitions, subscriptions
Resolves Issues:

* https://github.com/hasura/graphql-engine-mono/issues/658 - Invalid Slashes
* https://github.com/hasura/graphql-engine-mono/issues/628 - Subscriptions

Implementation:

* Moved some logic from Endpoint.hs to allow reuse of splitting url into PathSegments.
* Additional validation steps alongside checking for overlapping routes
* Logging potential misuse of GET for mutations

Future Work:

* [ ] GET is allowed for mutations (Ignore/Log warning for Now)
* [ ] Add to scInconsistentObjs rather than throwing error
  * Add information to scInconsistentObjs instead of raising errors directly.

TODO:

* [x] Duplicate variable segments with the same name in the location should not be allowed
* [x] We should throw an error on trailing and leading slashes and URLs which contain empty segments
* [x] Endpoints can be created using subscriptions. But the error only shows at the time of the query
* [x] Tests

---

### Kodiak commit message

Prohibit Invalid slashes, duplicate variables, subscriptions for REST endpoints.

GitOrigin-RevId: 86c0d4af97984c8afd02699e6071e9c1658710b8
2021-02-24 04:31:05 +00:00

111 lines
2.4 KiB
YAML

type: bulk
args:
- type: create_query_collection
args:
name: test_collection
definition:
queries:
- name: simple_query
query: "query { test_table { first_name last_name } }"
- name: simple_query_cached
query: "query @cached(ttl: 5) { test_table { first_name last_name } }"
- name: query_with_arg
query: "query ($first_name:String!) { test_table(where: {first_name: { _eq: $first_name } }) { first_name last_name } }"
- name: query_with_args
query: "query ($first_name: String!, $last_name:String!) { test_table(where: {first_name: { _eq: $first_name } last_name: { _eq: $last_name }}) { first_name last_name } }"
- name: simple_subscription
query: "subscription { test_table { first_name last_name } }"
- type: create_rest_endpoint
args:
url: simple
name: simple
methods:
- GET
definition:
query:
collection_name: test_collection
query_name: simple_query
- type: create_rest_endpoint
args:
url: simple_cached
name: simple_cached
methods:
- GET
definition:
query:
collection_name: test_collection
query_name: simple_query_cached
- type: create_rest_endpoint
args:
url: with_arg
name: with_arg
methods:
- GET
- POST
definition:
query:
collection_name: test_collection
query_name: query_with_arg
- type: create_rest_endpoint
args:
url: with_args
name: with_args
methods:
- GET
definition:
query:
collection_name: test_collection
query_name: query_with_args
- type: create_rest_endpoint
args:
url: with_template/:first_name
name: with_template
methods:
- GET
definition:
query:
collection_name: test_collection
query_name: query_with_arg
- type: create_rest_endpoint
args:
url: to_be_dropped
name: to_be_dropped
methods:
- GET
definition:
query:
collection_name: test_collection
query_name: simple_query
- type: drop_rest_endpoint
args:
name: to_be_dropped
- type: run_sql
args:
sql: |
create table test_table(
first_name text,
last_name text
);
- type: track_table
args:
schema: public
name: test_table
- type: run_sql
args:
sql: |
insert into test_table (first_name, last_name)
values
('Foo', 'Bar'),
('Baz', 'Qux'),
('X%20Y', 'Test');