Skip to content

Commit

Permalink
Merge pull request #750 from Shopify/jbaker/update-introspection
Browse files Browse the repository at this point in the history
Update build process to use public introspection
  • Loading branch information
cocoahero authored Oct 6, 2023
2 parents 92ad686 + 31f8d0f commit 4ab0ed1
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 9 deletions.
3 changes: 2 additions & 1 deletion MobileBuy/buy3/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
source 'https://rubygems.org'

gem 'graphql_java_gen', path: '../libs/graphql_java_gen/'
gem 'faraday'
gem 'graphql_java_gen', path: '../libs/graphql_java_gen/'
10 changes: 9 additions & 1 deletion MobileBuy/buy3/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ PATH
GEM
remote: https://rubygems.org/
specs:
base64 (0.1.1)
faraday (2.7.11)
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
graphql_schema (0.1.8)
ruby2_keywords (0.0.5)

PLATFORMS
ruby

DEPENDENCIES
faraday
graphql_java_gen!

BUNDLED WITH
2.2.28
2.3.4
100 changes: 100 additions & 0 deletions MobileBuy/buy3/introspection.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
query IntrospectionQuery {
__schema {
queryType {
name
}
mutationType {
name
}
subscriptionType {
name
}
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields(includeDeprecated: true) {
...InputValue
isDeprecated
deprecationReason
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type {
...TypeRef
}
defaultValue
isDeprecated
deprecationReason
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
26 changes: 19 additions & 7 deletions MobileBuy/buy3/update_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'graphql_schema'
require 'json'
require 'optparse'
require 'net/http'
require 'faraday'
require 'fileutils'

target_filename = '../buy3/src/main/java/com/shopify/buy3/Storefront.java'
Expand All @@ -15,17 +15,29 @@
end
end.parse!

shared_storefront_api_key = "4a6c829ec3cb12ef9004bf8ed27adf12"
storefront_domain = "graphql.myshopify.com"
storefront_access_token = "3a109d5ebb8117f935adc1df233f3dfc"
storefront_api_version = ARGV[0]

abort("Error: API Version not specified") if storefront_api_version.nil? or storefront_api_version.empty?
introspection_query = File.read(File.join(__dir__, 'introspection.graphql'))

uri = URI("https://app.shopify.com/services/graphql/introspection/storefront?api_client_api_key=#{shared_storefront_api_key}&api_version=#{storefront_api_version}")
conn = Faraday.new(
url: "https://#{storefront_domain}/api/#{storefront_api_version}/",
headers: {
'Accept' => 'application/json',
'Content-Type' => 'application/graphql',
'X-Shopify-Storefront-Access-Token' => storefront_access_token
}
)

response = Net::HTTP.get_response(uri)
abort("Error fetching details for the api version #{storefront_api_version}") unless response.kind_of? Net::HTTPSuccess
res = conn.post('graphql') do |req|
req.body = introspection_query
end

abort "failed to introspect schema" unless res.success?

schema = GraphQLSchema.new(JSON.parse(res.body))

schema = GraphQLSchema.new(JSON.parse(response.body))
custom_scalars = [
GraphQLJavaGen::Scalar.new(
type_name: 'Money',
Expand Down

0 comments on commit 4ab0ed1

Please sign in to comment.