Module: ShopifyAPI::GraphQL
- Defined in:
- lib/shopify_api/graphql.rb,
lib/shopify_api/graphql/railtie.rb,
lib/shopify_api/graphql/http_client.rb
Defined Under Namespace
Classes: HTTPClient, Railtie
Constant Summary
collapse
- DEFAULT_SCHEMA_LOCATION_PATH =
Pathname('shopify_graphql_schemas')
- DEFAULT_EXECUTION_ADAPTER =
HTTPClient
- DEFAULT_GRAPHQL_CLIENT =
::GraphQL::Client
- InvalidSchema =
Class.new(StandardError)
- InvalidClient =
Class.new(StandardError)
Class Method Summary
collapse
Class Method Details
.clear_clients ⇒ Object
43
44
45
|
# File 'lib/shopify_api/graphql.rb', line 43
def clear_clients
@_client_cache = {}
end
|
.client(api_version = ShopifyAPI::Base.api_version.handle) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/shopify_api/graphql.rb', line 17
def client(api_version = ShopifyAPI::Base.api_version.handle)
initialize_client_cache
cached_client = @_client_cache[api_version]
if cached_client
cached_client
else
schema_file = schema_location.join("#{api_version}.json")
if !schema_file.exist?
raise InvalidClient, " Client for API version \#{api_version} does not exist because no schema file exists at `\#{schema_file}`.\n\n To dump the schema file, use the `rake shopify_api:graphql:dump` task.\n MSG\n else\n puts(\n '[WARNING] Client was not pre-initialized. Ensure `ShopifyAPI::GraphQL.initialize_clients` ' \\\n 'is called during app initialization.'\n )\n initialize_clients\n @_client_cache[api_version]\n end\n end\nend\n"
|
.execution_adapter ⇒ Object
80
81
82
|
# File 'lib/shopify_api/graphql.rb', line 80
def execution_adapter
@execution_adapter || DEFAULT_EXECUTION_ADAPTER
end
|
.execution_adapter=(executor) ⇒ Object
84
85
86
|
# File 'lib/shopify_api/graphql.rb', line 84
def execution_adapter=(executor)
@execution_adapter = executor
end
|
.graphql_client ⇒ Object
88
89
90
|
# File 'lib/shopify_api/graphql.rb', line 88
def graphql_client
@graphql_client || DEFAULT_GRAPHQL_CLIENT
end
|
.graphql_client=(client) ⇒ Object
92
93
94
|
# File 'lib/shopify_api/graphql.rb', line 92
def graphql_client=(client)
@graphql_client = client
end
|
.initialize_clients(raise_on_invalid_schema: true) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/shopify_api/graphql.rb', line 47
def initialize_clients(raise_on_invalid_schema: true)
initialize_client_cache
Dir.glob(schema_location.join("*.json")).each do |schema_file|
schema_file = Pathname(schema_file)
matches = schema_file.basename.to_s.match(/^#{ShopifyAPI::ApiVersion::HANDLE_FORMAT}\.json$/)
if matches
api_version = ShopifyAPI::ApiVersion.new(handle: matches[1])
elsif raise_on_invalid_schema
raise InvalidSchema,
"Invalid schema file name `#{schema_file}`. Does not match format of: `<version>.json`."
else
next
end
schema = graphql_client.load_schema(schema_file.to_s)
client = graphql_client.new(schema: schema, execute: execution_adapter.new(api_version)).tap do |c|
c.allow_dynamic_queries = true
end
@_client_cache[api_version.handle] = client
end
end
|
.schema_location ⇒ Object
72
73
74
|
# File 'lib/shopify_api/graphql.rb', line 72
def schema_location
@schema_location || DEFAULT_SCHEMA_LOCATION_PATH
end
|
.schema_location=(path) ⇒ Object
76
77
78
|
# File 'lib/shopify_api/graphql.rb', line 76
def schema_location=(path)
@schema_location = Pathname(path)
end
|