graphql_scaffold_fan 0.2.5 → 0.2.8
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/generators/graphql_scaffold/init_generator.rb +22 -0
- data/lib/generators/graphql_scaffold/mutation_generator.rb +2 -9
- data/lib/generators/graphql_scaffold/type_generator.rb +5 -3
- data/lib/generators/templates/admin_schema.haml +13 -11
- data/lib/generators/templates/mutation_create_test.haml +0 -1
- data/lib/generators/templates/mutation_delete_test.haml +0 -2
- data/lib/generators/templates/mutation_type.haml +1 -1
- data/lib/generators/templates/mutation_update_test.haml +0 -1
- data/lib/generators/templates/query_type.haml +1 -1
- data/lib/graphql_scaffold_fan/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: dcfe0933232990b0284c47835fed6627498363ee486604fafa3d5dd60c268aba
         | 
| 4 | 
            +
              data.tar.gz: ff168a50bb8759d30a95e5f3d346565d75bc350fce76a54dd2348ed1c6070eb0
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: bbc4d8acb3b29d051c3bc05a01c3e8aeb9c8e7e52f770b48ec311e8f3a8522933855b3f6693169ce4085f1fd184620dc33e46378267e385799a7794d4e48f096
         | 
| 7 | 
            +
              data.tar.gz: 772501a125b03fa195c19b8cd45881746e31a92a5a485206eeea58f69435f8b6bd5cfb3f1b26f18bd165d3a53f18ca0c9fe040e6788ddc569275bb713eb43a1b
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -40,6 +40,28 @@ module GraphqlScaffold | |
| 40 40 | 
             
                    end
         | 
| 41 41 | 
             
                  end
         | 
| 42 42 |  | 
| 43 | 
            +
                  def create_mutation_type_file
         | 
| 44 | 
            +
                    mutation_type_dir_path = 'app/graphql/types/admin'
         | 
| 45 | 
            +
                    generator_dir_path = mutation_type_dir_path
         | 
| 46 | 
            +
                    generator_path = generator_dir_path + '/mutation_type.rb'
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                    FileUtils.mkdir_p(mutation_type_dir_path) unless File.exist?(mutation_type_dir_path)
         | 
| 49 | 
            +
                    FileUtils.mkdir_p(generator_dir_path) unless File.exist?(generator_dir_path)
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                    template 'mutation_type.haml', generator_path if !File.exist?(generator_path)
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  def create_query_type_file
         | 
| 55 | 
            +
                    query_type_dir_path = 'app/graphql/types/admin'
         | 
| 56 | 
            +
                    generator_dir_path = query_type_dir_path
         | 
| 57 | 
            +
                    generator_path = generator_dir_path + '/query_type.rb'
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    FileUtils.mkdir_p(query_type_dir_path) unless File.exist?(query_type_dir_path)
         | 
| 60 | 
            +
                    FileUtils.mkdir_p(generator_dir_path) unless File.exist?(generator_dir_path)
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    template 'query_type.haml', generator_path if !File.exist?(generator_path)
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 43 65 | 
             
                  def add_route
         | 
| 44 66 | 
             
                    route_dir_path = 'config'
         | 
| 45 67 | 
             
                    route_file_path = route_dir_path + '/routes.rb'
         | 
| @@ -22,7 +22,7 @@ module GraphqlScaffold | |
| 22 22 | 
             
                    generator_dir_path = admin_mutation_dir_path + ("/#{@module_name.underscore}" if @module_name.present?).to_s
         | 
| 23 23 | 
             
                    @generator_path = generator_dir_path + "/#{file_name}s"
         | 
| 24 24 |  | 
| 25 | 
            -
                    admin_mutation_test_dir_path = 'spec/ | 
| 25 | 
            +
                    admin_mutation_test_dir_path = 'spec/requests/mutations/admin'
         | 
| 26 26 | 
             
                    generator_test_dir_path = admin_mutation_test_dir_path + (if @module_name.present?
         | 
| 27 27 | 
             
                                                                                "/#{@module_name.underscore}"
         | 
| 28 28 | 
             
                                                                              end).to_s
         | 
| @@ -104,7 +104,7 @@ module GraphqlScaffold | |
| 104 104 | 
             
                    end
         | 
| 105 105 | 
             
                  end
         | 
| 106 106 |  | 
| 107 | 
            -
                  def  | 
| 107 | 
            +
                  def write_to_mutation_type_file
         | 
| 108 108 | 
             
                    mutation_type_dir_path = 'app/graphql/types/admin'
         | 
| 109 109 | 
             
                    generator_dir_path = mutation_type_dir_path
         | 
| 110 110 | 
             
                    generator_path = generator_dir_path + '/mutation_type.rb'
         | 
| @@ -122,13 +122,6 @@ module GraphqlScaffold | |
| 122 122 | 
             
                      template 'mutation_type.haml', generator_path
         | 
| 123 123 | 
             
                    end
         | 
| 124 124 | 
             
                  end
         | 
| 125 | 
            -
             | 
| 126 | 
            -
                  def create_test_file
         | 
| 127 | 
            -
                    test_dir_path = 'spec/requests/mutations'
         | 
| 128 | 
            -
                    test_file_path = test_dir_path + "/#{file_name}_spec.rb"
         | 
| 129 | 
            -
                    FileUtils.mkdir_p(test_dir_path) unless File.exist?(test_dir_path)
         | 
| 130 | 
            -
                    template 'mutation_test.haml', test_file_path
         | 
| 131 | 
            -
                  end
         | 
| 132 125 | 
             
                end
         | 
| 133 126 | 
             
              end
         | 
| 134 127 | 
             
            end
         | 
| @@ -11,10 +11,12 @@ module GraphqlScaffold | |
| 11 11 | 
             
                      dst_dir = 'app/graphql/types/admin'
         | 
| 12 12 | 
             
                      if File.exist?("app/graphql/types/#{file_name}_type.rb")
         | 
| 13 13 | 
             
                        FileUtils.mv(src_file, dst_dir)
         | 
| 14 | 
            +
                        p "Move #{file_name}_type.rb location"
         | 
| 14 15 | 
             
                        file = File.open("#{dst_dir}/#{file_name}_type.rb")
         | 
| 15 16 | 
             
                        file_data = file.read
         | 
| 16 | 
            -
                        new_file_data = file_data.insert( | 
| 17 | 
            +
                        new_file_data = file_data.insert(52, 'Admin::')
         | 
| 17 18 | 
             
                        File.write(file, new_file_data)
         | 
| 19 | 
            +
                        p "Write to #{file_name}_type.rb"
         | 
| 18 20 | 
             
                      else
         | 
| 19 21 | 
             
                        p "can not find #{file_name}_type file to move"
         | 
| 20 22 | 
             
                      end
         | 
| @@ -36,7 +38,7 @@ module GraphqlScaffold | |
| 36 38 | 
             
                    template 'admin_filter.haml', generator_path
         | 
| 37 39 | 
             
                  end
         | 
| 38 40 |  | 
| 39 | 
            -
                  def  | 
| 41 | 
            +
                  def write_to_query_type_file
         | 
| 40 42 | 
             
                    query_type_dir_path = 'app/graphql/types/admin'
         | 
| 41 43 | 
             
                    generator_dir_path = query_type_dir_path
         | 
| 42 44 | 
             
                    generator_path = generator_dir_path + '/query_type.rb'
         | 
| @@ -67,7 +69,7 @@ module GraphqlScaffold | |
| 67 69 | 
             
                  end
         | 
| 68 70 |  | 
| 69 71 | 
             
                  def create_test_file
         | 
| 70 | 
            -
                    test_dir_path = 'spec/requests/queries'
         | 
| 72 | 
            +
                    test_dir_path = 'spec/requests/queries/admin'
         | 
| 71 73 | 
             
                    test_file_path = test_dir_path + "/#{file_name}_spec.rb"
         | 
| 72 74 | 
             
                    FileUtils.mkdir_p(test_dir_path) unless File.exist?(test_dir_path)
         | 
| 73 75 | 
             
                    template 'query_test.haml', test_file_path
         | 
| @@ -4,17 +4,19 @@ | |
| 4 4 | 
             
            class <%= class_name %>AdminSchema < GraphQL::Schema
         | 
| 5 5 | 
             
              use GraphQL::Tracing::NewRelicTracing, set_transaction_name: true
         | 
| 6 6 | 
             
              use GraphqlDevise::SchemaPlugin.new(
         | 
| 7 | 
            -
                query: | 
| 8 | 
            -
                mutation: | 
| 7 | 
            +
                query:            Types::Admin::QueryType,
         | 
| 8 | 
            +
                mutation:         Types::Admin::MutationType,
         | 
| 9 9 | 
             
                resource_loaders: [
         | 
| 10 | 
            -
                  GraphqlDevise::ResourceLoader.new(AdminUser, | 
| 10 | 
            +
                  GraphqlDevise::ResourceLoader.new(AdminUser,
         | 
| 11 | 
            +
                                                    operations: {
         | 
| 12 | 
            +
                                                      login: Mutations::Admin::Auth::Login
         | 
| 13 | 
            +
                                                    },
         | 
| 14 | 
            +
                                                    only:       %i[login logout])
         | 
| 11 15 | 
             
                ]
         | 
| 12 16 | 
             
              )
         | 
| 13 17 |  | 
| 14 | 
            -
              mutation(Types:: | 
| 15 | 
            -
              query(Types:: | 
| 16 | 
            -
             | 
| 17 | 
            -
              use GraphQL::Batch
         | 
| 18 | 
            +
              mutation(Types::Admin::MutationType)
         | 
| 19 | 
            +
              query(Types::Admin::QueryType)
         | 
| 18 20 |  | 
| 19 21 | 
             
              # Union and Interface Resolution
         | 
| 20 22 | 
             
              def self.resolve_type(_abstract_type, _obj, _ctx)
         | 
| @@ -26,17 +28,17 @@ class <%= class_name %>AdminSchema < GraphQL::Schema | |
| 26 28 | 
             
              # Relay-style Object Identification:
         | 
| 27 29 |  | 
| 28 30 | 
             
              # Return a string UUID for `object`
         | 
| 29 | 
            -
              def self.id_from_object(object, type_definition,  | 
| 31 | 
            +
              def self.id_from_object(object, type_definition, query_ctx)
         | 
| 30 32 | 
             
                # Here's a simple implementation which:
         | 
| 31 33 | 
             
                # - joins the type name & object.id
         | 
| 32 34 | 
             
                # - encodes it with base64:
         | 
| 33 | 
            -
                GraphQL::Schema::UniqueWithinType.encode(type_definition.name, object.id)
         | 
| 35 | 
            +
                # GraphQL::Schema::UniqueWithinType.encode(type_definition.name, object.id)
         | 
| 34 36 | 
             
              end
         | 
| 35 37 |  | 
| 36 38 | 
             
              # Given a string UUID, find the object
         | 
| 37 | 
            -
              def self.object_from_id(id,  | 
| 39 | 
            +
              def self.object_from_id(id, query_ctx)
         | 
| 38 40 | 
             
                # For example, to decode the UUIDs generated above:
         | 
| 39 | 
            -
                type_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
         | 
| 41 | 
            +
                # type_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
         | 
| 40 42 | 
             
                #
         | 
| 41 43 | 
             
                # Then, based on `type_name` and `id`
         | 
| 42 44 | 
             
                # find an object in your application
         | 
| @@ -13,7 +13,6 @@ RSpec.describe Mutations::Admin::<%= class_name %>s::Create<%= class_name %>, ty | |
| 13 13 | 
             
                  GQL
         | 
| 14 14 |  | 
| 15 15 | 
             
                  expect do
         | 
| 16 | 
            -
                    sign_in admin_user
         | 
| 17 16 | 
             
                    post '/api/admin/graphql', headers: admin_user.create_new_auth_token, params: { query: query, variables: variables }
         | 
| 18 17 | 
             
                    expect(response).to have_http_status(:success)
         | 
| 19 18 | 
             
                    json = JSON.parse(response.body)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: graphql_scaffold_fan
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.8
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Fan Zhang
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022- | 
| 11 | 
            +
            date: 2022-08-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: graphql
         |