Skip to content

Commit 99f4e82

Browse files
authored
add remote_schema_timeout (#369)
1 parent e4f5b5a commit 99f4e82

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Optional settings:
6464

6565
- `remote_schema_headers` - extra headers that are passed along with introspection query, eg. `{"Authorization" = "Bearer: token"}`. To include an environment variable in a header value, prefix the variable with `$`, eg. `{"Authorization" = "$AUTH_TOKEN"}`
6666
- `remote_schema_verify_ssl` (defaults to `true`) - a flag that specifies wheter to verify ssl while introspecting remote schema
67+
- `remote_schema_timeout` (defaults to `5`) - timeout in seconds while introspecting remote schema
6768
- `target_package_name` (defaults to `"graphql_client"`) - name of generated package
6869
- `target_package_path` (defaults to cwd) - path where to generate package
6970
- `client_name` (defaults to `"Client"`) - name of generated client class
@@ -418,7 +419,7 @@ Instead of generating a client, you can generate a file with a copy of a GraphQL
418419
ariadne-codegen graphqlschema
419420
```
420421

421-
`graphqlschema` mode reads configuration from the same place as [`client`](#configuration) but uses only `schema_path`, `remote_schema_url`, `remote_schema_headers`, `remote_schema_verify_ssl` options to retrieve the schema and `plugins` option to load plugins.
422+
`graphqlschema` mode reads configuration from the same place as [`client`](#configuration) but uses only `schema_path`, `remote_schema_url`, `remote_schema_headers`, `remote_schema_verify_ssl`, `remote_schema_timeout` options to retrieve the schema and `plugins` option to load plugins.
422423

423424
In addition to the above, `graphqlschema` mode also accepts additional settings specific to it:
424425

ariadne_codegen/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def client(config_dict):
5050
url=settings.remote_schema_url,
5151
headers=settings.remote_schema_headers,
5252
verify_ssl=settings.remote_schema_verify_ssl,
53+
timeout=settings.remote_schema_timeout
5354
)
5455

5556
plugin_manager = PluginManager(
@@ -93,6 +94,7 @@ def graphql_schema(config_dict):
9394
url=settings.remote_schema_url,
9495
headers=settings.remote_schema_headers,
9596
verify_ssl=settings.remote_schema_verify_ssl,
97+
timeout=settings.remote_schema_timeout
9698
)
9799
)
98100
plugin_manager = PluginManager(

ariadne_codegen/schema.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,32 @@ def get_graphql_queries(
6363

6464

6565
def get_graphql_schema_from_url(
66-
url: str, headers: Optional[Dict[str, str]] = None, verify_ssl: bool = True
66+
url: str,
67+
headers: Optional[Dict[str, str]] = None,
68+
verify_ssl: bool = True,
69+
timeout: float = 5,
6770
) -> GraphQLSchema:
6871
return build_client_schema(
69-
introspect_remote_schema(url=url, headers=headers, verify_ssl=verify_ssl),
72+
introspect_remote_schema(
73+
url=url, headers=headers, verify_ssl=verify_ssl, timeout=timeout
74+
),
7075
assume_valid=True,
7176
)
7277

7378

7479
def introspect_remote_schema(
75-
url: str, headers: Optional[Dict[str, str]] = None, verify_ssl: bool = True
80+
url: str,
81+
headers: Optional[Dict[str, str]] = None,
82+
verify_ssl: bool = True,
83+
timeout: float = 5,
7684
) -> IntrospectionQuery:
7785
try:
7886
response = httpx.post(
7987
url,
8088
json={"query": get_introspection_query(descriptions=False)},
8189
headers=headers,
8290
verify=verify_ssl,
91+
timeout=timeout,
8392
)
8493
except httpx.InvalidURL as exc:
8594
raise IntrospectionError(f"Invalid remote schema url: {url}") from exc

ariadne_codegen/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class BaseSettings:
3737
remote_schema_url: str = ""
3838
remote_schema_headers: dict = field(default_factory=dict)
3939
remote_schema_verify_ssl: bool = True
40+
remote_schema_timeout: float = 5
4041
enable_custom_operations: bool = False
4142
plugins: List[str] = field(default_factory=list)
4243

tests/client_generators/package_generator/test_generator_generation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def test_get_package_generator_without_default_settings(tmp_path: Path):
4545
remote_schema_url="remote_schema_url",
4646
remote_schema_headers={"header": "header"},
4747
remote_schema_verify_ssl=False,
48+
remote_schema_timeout=5,
4849
enable_custom_operations=True,
4950
plugins=["imaplugin"],
5051
queries_path=schema_path.as_posix(),

0 commit comments

Comments
 (0)