diff --git a/MobileBuy/buy3/Gemfile b/MobileBuy/buy3/Gemfile index 55be72dc..f2c026b5 100644 --- a/MobileBuy/buy3/Gemfile +++ b/MobileBuy/buy3/Gemfile @@ -1,3 +1,4 @@ source 'https://rubygems.org' -gem 'graphql_java_gen', path: '../libs/graphql_java_gen/' \ No newline at end of file +gem 'faraday' +gem 'graphql_java_gen', path: '../libs/graphql_java_gen/' diff --git a/MobileBuy/buy3/Gemfile.lock b/MobileBuy/buy3/Gemfile.lock index a8331315..eedb6be8 100644 --- a/MobileBuy/buy3/Gemfile.lock +++ b/MobileBuy/buy3/Gemfile.lock @@ -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 diff --git a/MobileBuy/buy3/introspection.graphql b/MobileBuy/buy3/introspection.graphql new file mode 100644 index 00000000..cb9f747a --- /dev/null +++ b/MobileBuy/buy3/introspection.graphql @@ -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 + } + } + } + } + } + } + } +} diff --git a/MobileBuy/buy3/update_schema.rb b/MobileBuy/buy3/update_schema.rb index 4470f09f..7e827cc9 100755 --- a/MobileBuy/buy3/update_schema.rb +++ b/MobileBuy/buy3/update_schema.rb @@ -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' @@ -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',