title: Using GraphQL to Filter a JSON Data in Python
body: <p>I'm using the official <code>graphene</code> package in my python project. I have a huge nested JSON data that comes from a running Docker container inspect command and I want to get some fields from that. I can select all those fields each by each and adding them to a dictionary like this:</p>
  <pre><code>def ContainerConfigs(configs):
      data = {}
      data['Command'] = configs['Args'][-1]
      data['Hostname'] = configs['Config']['Hostname']
      data['Image'] = configs['Config']['Image']
      data['Distro'] = configs['Config']['Labels']['org.label-schema.name']
      data['WorkDir'] = configs['Config']['WorkingDir']
      data['IPAddress'] = configs['NetworkSettings']['Networks']['bridge']['IPAddress']
  
      return data
  </code></pre>
  <p>But It's a weak solution. I think It can be optimized using GraphQL. There is no server, request, and response. I want to create its <code>Schema</code> class and send the parameters (JSON and Query) and let the function execute that query and turns back the result. Something like this:</p>
  <pre><code>import graphene
  
  # I need to find this part of the code
  # class Schema(..):
  #     ...
  # class Query(...):
  #     ...
  
  def ContainerConfigs(configs, query):
      schema = graphene.Schema(query=Query)
      # I need to find a way to pass the configs (Json data) to the Query class to
      # execute the query_string on the data
      query_string = &quot;&quot;&quot;
      query {
          Args
          Config {
              Hostname
              Image
              WorkingDir
              Label{
                  org.label-schema.name
              }
          }
          NetworkSettings{
              Networks{
                  bridge{
                      IPAddress
                  }
              }
          }
      }
      &quot;&quot;&quot;
      result = schema.execute(query_string)
      
      return result
  </code></pre>