graphql-http 2.1.2__tar.gz → 2.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. {graphql_http-2.1.2 → graphql_http-2.1.4}/PKG-INFO +1 -1
  2. graphql_http-2.1.4/VERSION +1 -0
  3. {graphql_http-2.1.2 → graphql_http-2.1.4}/graphql_http/graphiql/index.html +43 -1
  4. {graphql_http-2.1.2 → graphql_http-2.1.4}/graphql_http.egg-info/PKG-INFO +1 -1
  5. {graphql_http-2.1.2 → graphql_http-2.1.4}/graphql_http.egg-info/SOURCES.txt +0 -5
  6. {graphql_http-2.1.2 → graphql_http-2.1.4}/tests/test_server.py +29 -0
  7. graphql_http-2.1.2/VERSION +0 -1
  8. graphql_http-2.1.2/example.graphql +0 -6
  9. graphql_http-2.1.2/test_auto_discovery.py +0 -29
  10. graphql_http-2.1.2/test_cwd_issue.py +0 -68
  11. graphql_http-2.1.2/test_html_output.py +0 -72
  12. graphql_http-2.1.2/test_logging.py +0 -49
  13. {graphql_http-2.1.2 → graphql_http-2.1.4}/.coverage +0 -0
  14. {graphql_http-2.1.2 → graphql_http-2.1.4}/.github/workflows/pages.yml +0 -0
  15. {graphql_http-2.1.2 → graphql_http-2.1.4}/.github/workflows/python-package.yml +0 -0
  16. {graphql_http-2.1.2 → graphql_http-2.1.4}/.gitignore +0 -0
  17. {graphql_http-2.1.2 → graphql_http-2.1.4}/.gitmodules +0 -0
  18. {graphql_http-2.1.2 → graphql_http-2.1.4}/LICENSE +0 -0
  19. {graphql_http-2.1.2 → graphql_http-2.1.4}/README.md +0 -0
  20. {graphql_http-2.1.2 → graphql_http-2.1.4}/docs/.gitmodules +0 -0
  21. {graphql_http-2.1.2 → graphql_http-2.1.4}/docs/content/_index.md +0 -0
  22. {graphql_http-2.1.2 → graphql_http-2.1.4}/docs/content/docs/_index.md +0 -0
  23. {graphql_http-2.1.2 → graphql_http-2.1.4}/docs/content/docs/api-reference.md +0 -0
  24. {graphql_http-2.1.2 → graphql_http-2.1.4}/docs/content/docs/authentication.md +0 -0
  25. {graphql_http-2.1.2 → graphql_http-2.1.4}/docs/content/docs/configuration.md +0 -0
  26. {graphql_http-2.1.2 → graphql_http-2.1.4}/docs/content/docs/examples.md +0 -0
  27. {graphql_http-2.1.2 → graphql_http-2.1.4}/docs/content/docs/getting-started.md +0 -0
  28. {graphql_http-2.1.2 → graphql_http-2.1.4}/docs/content/docs/testing.md +0 -0
  29. {graphql_http-2.1.2 → graphql_http-2.1.4}/docs/hugo.toml +0 -0
  30. {graphql_http-2.1.2 → graphql_http-2.1.4}/docs/index.md +0 -0
  31. {graphql_http-2.1.2 → graphql_http-2.1.4}/examples/README.md +0 -0
  32. {graphql_http-2.1.2 → graphql_http-2.1.4}/examples/__init__.py +0 -0
  33. {graphql_http-2.1.2 → graphql_http-2.1.4}/examples/advanced_server.py +0 -0
  34. {graphql_http-2.1.2 → graphql_http-2.1.4}/examples/auth_server.py +0 -0
  35. {graphql_http-2.1.2 → graphql_http-2.1.4}/examples/basic_server.py +0 -0
  36. {graphql_http-2.1.2 → graphql_http-2.1.4}/examples/graphql_api_server.py +0 -0
  37. {graphql_http-2.1.2 → graphql_http-2.1.4}/graphql_http/__init__.py +0 -0
  38. {graphql_http-2.1.2 → graphql_http-2.1.4}/graphql_http/error.py +0 -0
  39. {graphql_http-2.1.2 → graphql_http-2.1.4}/graphql_http/helpers.py +0 -0
  40. {graphql_http-2.1.2 → graphql_http-2.1.4}/graphql_http/introspection.py +0 -0
  41. {graphql_http-2.1.2 → graphql_http-2.1.4}/graphql_http/server.py +0 -0
  42. {graphql_http-2.1.2 → graphql_http-2.1.4}/graphql_http.egg-info/dependency_links.txt +0 -0
  43. {graphql_http-2.1.2 → graphql_http-2.1.4}/graphql_http.egg-info/requires.txt +0 -0
  44. {graphql_http-2.1.2 → graphql_http-2.1.4}/graphql_http.egg-info/top_level.txt +0 -0
  45. {graphql_http-2.1.2 → graphql_http-2.1.4}/pyproject.toml +0 -0
  46. {graphql_http-2.1.2 → graphql_http-2.1.4}/setup.cfg +0 -0
  47. {graphql_http-2.1.2 → graphql_http-2.1.4}/test_server.py +0 -0
  48. {graphql_http-2.1.2 → graphql_http-2.1.4}/tests/__init__.py +0 -0
  49. {graphql_http-2.1.2 → graphql_http-2.1.4}/tests/app.py +0 -0
  50. {graphql_http-2.1.2 → graphql_http-2.1.4}/tests/app_federation.py +0 -0
  51. {graphql_http-2.1.2 → graphql_http-2.1.4}/tests/conftest.py +0 -0
  52. {graphql_http-2.1.2 → graphql_http-2.1.4}/tests/test_auth.py +0 -0
  53. {graphql_http-2.1.2 → graphql_http-2.1.4}/tests/test_cors.py +0 -0
  54. {graphql_http-2.1.2 → graphql_http-2.1.4}/tests/test_examples.py +0 -0
  55. {graphql_http-2.1.2 → graphql_http-2.1.4}/tests/test_federation.py +0 -0
  56. {graphql_http-2.1.2 → graphql_http-2.1.4}/tests/test_graphql_api.py +0 -0
  57. {graphql_http-2.1.2 → graphql_http-2.1.4}/tests/test_introspection.py +0 -0
  58. {graphql_http-2.1.2 → graphql_http-2.1.4}/tests/test_linting.py +0 -0
  59. {graphql_http-2.1.2 → graphql_http-2.1.4}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graphql-http
3
- Version: 2.1.2
3
+ Version: 2.1.4
4
4
  Summary: HTTP Server for GraphQL.
5
5
  Author-email: Robert Parker <rob@parob.com>
6
6
  License: MIT
@@ -0,0 +1 @@
1
+ 2.1.4
@@ -3626,13 +3626,55 @@
3626
3626
  });
3627
3627
  const plugins = [HISTORY_PLUGIN, explorerPlugin(), sdlDownloadPlugin, schemaVisualizerPlugin];
3628
3628
 
3629
+ // Store the default query so we can use it in the storage wrapper
3630
+ const defaultQueryValue = "DEFAULT_QUERY";
3631
+
3632
+ // Custom storage that replaces empty queries with defaultQuery
3633
+ const customStorage = {
3634
+ ...localStorage,
3635
+ getItem(key) {
3636
+ const value = localStorage.getItem(key);
3637
+
3638
+ // Handle GraphiQL tab state - replace empty query with default
3639
+ if (key === 'graphiql:tabState' && value) {
3640
+ try {
3641
+ const tabState = JSON.parse(value);
3642
+ if (tabState && tabState.tabs && Array.isArray(tabState.tabs)) {
3643
+ const activeIndex = tabState.activeTabIndex || 0;
3644
+ const activeTab = tabState.tabs[activeIndex];
3645
+
3646
+ // If the active tab's query is empty or whitespace, replace it with defaultQuery
3647
+ if (activeTab && (!activeTab.query || activeTab.query.trim() === '')) {
3648
+ activeTab.query = defaultQueryValue;
3649
+ const updatedValue = JSON.stringify(tabState);
3650
+ localStorage.setItem(key, updatedValue);
3651
+ return updatedValue;
3652
+ }
3653
+ }
3654
+ } catch (e) {
3655
+ // If parsing fails, just return the value as-is
3656
+ return value;
3657
+ }
3658
+ }
3659
+
3660
+ return value;
3661
+ },
3662
+ setItem(key, value) {
3663
+ return localStorage.setItem(key, value);
3664
+ },
3665
+ removeItem(key) {
3666
+ return localStorage.removeItem(key);
3667
+ }
3668
+ };
3669
+
3629
3670
  function App() {
3630
3671
  return React.createElement(GraphiQL, {
3631
3672
  fetcher,
3632
3673
  plugins,
3633
3674
  defaultEditorToolsVisibility: false,
3634
3675
  isHeadersEditorEnabled: true,
3635
- defaultQuery: "DEFAULT_QUERY"
3676
+ defaultQuery: defaultQueryValue,
3677
+ storage: customStorage
3636
3678
  });
3637
3679
  }
3638
3680
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graphql-http
3
- Version: 2.1.2
3
+ Version: 2.1.4
4
4
  Summary: HTTP Server for GraphQL.
5
5
  Author-email: Robert Parker <rob@parob.com>
6
6
  License: MIT
@@ -4,12 +4,7 @@
4
4
  LICENSE
5
5
  README.md
6
6
  VERSION
7
- example.graphql
8
7
  pyproject.toml
9
- test_auto_discovery.py
10
- test_cwd_issue.py
11
- test_html_output.py
12
- test_logging.py
13
8
  test_server.py
14
9
  uv.lock
15
10
  .github/workflows/pages.yml
@@ -560,3 +560,32 @@ class TestGraphQLHTTPConfiguration:
560
560
  data = {"hello": "world"}
561
561
  encoded = GraphQLHTTP.encode(data)
562
562
  assert encoded == '{"hello":"world"}'
563
+
564
+ def test_graphiql_custom_storage_for_empty_localstorage(self, basic_schema):
565
+ """Test that GraphiQL HTML includes custom storage to handle empty localStorage."""
566
+ example_query = "query Example { hello }"
567
+ server = GraphQLHTTP(
568
+ schema=basic_schema,
569
+ graphiql_example_query=example_query
570
+ )
571
+ client = server.client()
572
+
573
+ response = client.get("/graphql", headers={"Accept": "text/html"})
574
+ assert response.status_code == 200
575
+ assert "text/html" in response.headers["content-type"]
576
+
577
+ # Verify defaultQueryValue variable is defined
578
+ assert "defaultQueryValue" in response.text
579
+
580
+ # Verify custom storage implementation is present
581
+ assert "customStorage" in response.text
582
+ assert "graphiql:tabState" in response.text
583
+ assert "storage: customStorage" in response.text
584
+
585
+ # Verify the storage checks for empty query values and replaces with default
586
+ assert "JSON.parse" in response.text
587
+ assert "activeTab.query" in response.text
588
+ assert "activeTab.query = defaultQueryValue" in response.text
589
+
590
+ # Verify the example query is still in the HTML
591
+ assert "Example" in response.text
@@ -1 +0,0 @@
1
- 2.1.2
@@ -1,6 +0,0 @@
1
- query ExampleQuery {
2
- # This is an auto-discovered example query!
3
- # Just create example.graphql or graphiql_example.graphql
4
- # in the directory where you run your app
5
- hello
6
- }
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Quick test to demonstrate auto-discovery of example.graphql"""
3
-
4
- from graphql import GraphQLSchema, GraphQLObjectType, GraphQLField, GraphQLString
5
- from graphql_http import GraphQLHTTP
6
-
7
- # Create a simple schema
8
- schema = GraphQLSchema(
9
- query=GraphQLObjectType(
10
- name="Query",
11
- fields={
12
- "hello": GraphQLField(
13
- GraphQLString,
14
- resolve=lambda obj, info: "Hello, World!"
15
- )
16
- }
17
- )
18
- )
19
-
20
- # Create server WITHOUT specifying graphiql_example_query
21
- # It should auto-discover the example.graphql file
22
- server = GraphQLHTTP(schema=schema)
23
-
24
- # Test that the example query was loaded
25
- if server.graphiql_example_query:
26
- print("✓ Auto-discovery SUCCESS!")
27
- print(f"\nLoaded example query:\n{server.graphiql_example_query}")
28
- else:
29
- print("✗ Auto-discovery failed - no example query found")
@@ -1,68 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Test to show the current working directory dependency"""
3
-
4
- import os
5
- import tempfile
6
- from graphql import GraphQLSchema, GraphQLObjectType, GraphQLField, GraphQLString
7
- from graphql_http import GraphQLHTTP
8
-
9
- # Create a simple schema
10
- schema = GraphQLSchema(
11
- query=GraphQLObjectType(
12
- name="Query",
13
- fields={
14
- "hello": GraphQLField(
15
- GraphQLString,
16
- resolve=lambda obj, info: "Hello, World!"
17
- )
18
- }
19
- )
20
- )
21
-
22
- print("Test 1: Server created from repo root (where example.graphql exists)")
23
- print(f"CWD: {os.getcwd()}")
24
- server1 = GraphQLHTTP(schema=schema)
25
- print(f"Example query loaded: {server1.graphiql_example_query is not None}")
26
- if server1.graphiql_example_query:
27
- print(f"✓ Query found: {server1.graphiql_example_query.split(chr(10))[0]}")
28
- else:
29
- print("✗ No query found")
30
-
31
- print("\n" + "="*80 + "\n")
32
-
33
- # Now change to a different directory
34
- original_cwd = os.getcwd()
35
- with tempfile.TemporaryDirectory() as tmpdir:
36
- os.chdir(tmpdir)
37
- print("Test 2: Server created from temp directory (no example.graphql)")
38
- print(f"CWD: {os.getcwd()}")
39
- server2 = GraphQLHTTP(schema=schema)
40
- print(f"Example query loaded: {server2.graphiql_example_query is not None}")
41
- if server2.graphiql_example_query:
42
- print(f"✓ Query found: {server2.graphiql_example_query.split(chr(10))[0]}")
43
- else:
44
- print("✗ No query found - THIS IS THE ISSUE!")
45
-
46
- print("\n" + "="*80 + "\n")
47
-
48
- # Now create example.graphql in the temp directory
49
- with open("example.graphql", "w") as f:
50
- f.write("query TestInTmpDir { hello }")
51
-
52
- print("Test 3: Server created after adding example.graphql to temp directory")
53
- print(f"CWD: {os.getcwd()}")
54
- print(f"Files in CWD: {os.listdir('.')}")
55
- server3 = GraphQLHTTP(schema=schema)
56
- print(f"Example query loaded: {server3.graphiql_example_query is not None}")
57
- if server3.graphiql_example_query:
58
- print(f"✓ Query found: {server3.graphiql_example_query}")
59
- else:
60
- print("✗ No query found")
61
-
62
- os.chdir(original_cwd)
63
-
64
- print("\n" + "="*80 + "\n")
65
- print("CONCLUSION:")
66
- print("The example.graphql file MUST be in the current working directory")
67
- print("when the GraphQLHTTP server is initialized, NOT necessarily where")
68
- print("your Python script is located!")
@@ -1,72 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Test to verify the example query appears in the actual HTML output"""
3
-
4
- from graphql import GraphQLSchema, GraphQLObjectType, GraphQLField, GraphQLString
5
- from graphql_http import GraphQLHTTP
6
-
7
- # Create a simple schema
8
- schema = GraphQLSchema(
9
- query=GraphQLObjectType(
10
- name="Query",
11
- fields={
12
- "hello": GraphQLField(
13
- GraphQLString,
14
- resolve=lambda obj, info: "Hello, World!"
15
- )
16
- }
17
- )
18
- )
19
-
20
- # Create server - should auto-discover example.graphql
21
- server = GraphQLHTTP(schema=schema)
22
- client = server.client()
23
-
24
- # Make a GET request to /graphql (which should serve GraphiQL)
25
- response = client.get("/graphql", headers={"Accept": "text/html"})
26
-
27
- print("Response status:", response.status_code)
28
- print("Content-Type:", response.headers.get("content-type"))
29
- print("\n" + "="*80)
30
-
31
- # Check if the example query is in the HTML
32
- if "ExampleQuery" in response.text:
33
- print("✓ SUCCESS: Example query found in HTML!")
34
-
35
- # Find and print the relevant section
36
- import re
37
- # Look for the defaultQuery line
38
- match = re.search(r'defaultQuery:\s*"([^"]*)"', response.text)
39
- if match:
40
- query_in_html = match.group(1)
41
- print(f"\ndefaultQuery value in HTML:\n{query_in_html}")
42
- else:
43
- print("\nCouldn't find defaultQuery pattern, searching for ExampleQuery context...")
44
- # Find context around ExampleQuery
45
- idx = response.text.find("ExampleQuery")
46
- if idx != -1:
47
- start = max(0, idx - 100)
48
- end = min(len(response.text), idx + 200)
49
- print(f"\nContext around 'ExampleQuery':\n{response.text[start:end]}")
50
- else:
51
- print("✗ FAILURE: Example query NOT found in HTML!")
52
- print("\nSearching for DEFAULT_QUERY placeholder...")
53
- if "DEFAULT_QUERY" in response.text:
54
- print("Found DEFAULT_QUERY - the replacement didn't happen!")
55
- # Show context
56
- idx = response.text.find("DEFAULT_QUERY")
57
- start = max(0, idx - 100)
58
- end = min(len(response.text), idx + 100)
59
- print(f"\nContext:\n{response.text[start:end]}")
60
- else:
61
- print("DEFAULT_QUERY not found either. Looking for defaultQuery...")
62
- import re
63
- match = re.search(r'defaultQuery:\s*"([^"]*)"', response.text)
64
- if match:
65
- print(f"\nFound defaultQuery: '{match.group(1)}'")
66
- else:
67
- print("Could not find defaultQuery in HTML")
68
-
69
- print("\n" + "="*80)
70
- print(f"\nServer's graphiql_example_query attribute:")
71
- print(f"Type: {type(server.graphiql_example_query)}")
72
- print(f"Value:\n{server.graphiql_example_query}")
@@ -1,49 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Test the improved auto-discovery logging"""
3
-
4
- import os
5
- import logging
6
- import tempfile
7
- from graphql import GraphQLSchema, GraphQLObjectType, GraphQLField, GraphQLString
8
- from graphql_http import GraphQLHTTP
9
-
10
- # Enable debug logging
11
- logging.basicConfig(
12
- level=logging.DEBUG,
13
- format='%(name)s - %(levelname)s - %(message)s'
14
- )
15
-
16
- # Create a simple schema
17
- schema = GraphQLSchema(
18
- query=GraphQLObjectType(
19
- name="Query",
20
- fields={
21
- "hello": GraphQLField(
22
- GraphQLString,
23
- resolve=lambda obj, info: "Hello, World!"
24
- )
25
- }
26
- )
27
- )
28
-
29
- print("="*80)
30
- print("TEST 1: Server created from repo root (where example.graphql exists)")
31
- print("="*80)
32
- server1 = GraphQLHTTP(schema=schema)
33
- print(f"\n✓ Example query loaded: {server1.graphiql_example_query is not None}\n")
34
-
35
- print("="*80)
36
- print("TEST 2: Server created from temp directory (no example.graphql)")
37
- print("="*80)
38
-
39
- original_cwd = os.getcwd()
40
- with tempfile.TemporaryDirectory() as tmpdir:
41
- os.chdir(tmpdir)
42
- server2 = GraphQLHTTP(schema=schema)
43
- print(f"\n✗ Example query loaded: {server2.graphiql_example_query is not None}\n")
44
-
45
- os.chdir(original_cwd)
46
-
47
- print("="*80)
48
- print("Notice the debug messages showing where it looked!")
49
- print("="*80)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes