Coder Social home page Coder Social logo

abn / aiographql-client Goto Github PK

View Code? Open in Web Editor NEW
27.0 2.0 13.0 709 KB

An asynchronous GraphQL client built on top of aiohttp and graphql-core-next

Home Page: https://aiographql-client.readthedocs.io/

License: MIT License

Python 98.45% Dockerfile 0.32% JavaScript 1.23%
aiohttp-client graphql asyncio python3 graphql-core hacktoberfest

aiographql-client's People

Contributors

abn avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar joshainglis avatar lucasmarshall avatar mariasoul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

aiographql-client's Issues

Add support for custom JSON serializers

Hello!

I have a use case that requires the serialization of uuid.UUIDs and Python's json cannot serialize them.
While I can str(uuid) before-hand, I think adding support for multiple json serializers is a plus (e.g. orjson is much faster and supports more types).

Would this be a feature you're interested in?

Get deserialised typed objects from GraphQLResponse

Apologies if this is somewhere in the documentation and I've missed it, but I am trying to parse a GraphQLResponse, and convert it into proper typed object from the schema definition that is in the client. I can call schema.get_type("my_type") from graphql-core but not sure how to deserialise the dict contained into GraphQLResponse to that. If we are passing schema in the client is this something that could be natively done?

Allow disabling introspection

Hi,

The graphql server I'm querying has introspection disabled. I'd like to still be able to use aiograhql.

Thanks!

Unclosed client session client_session: <aiohttp.client.ClientSession..>

Example of the code:

      client = GraphQLClient(
            endpoint=graphql_endpoint,
            headers=self.auth_headers

        )
        request = GraphQLRequest(
            query="""
            query doSearchIdentities($person: Person!, $address: Address!) {
              normalize(person: $person, address: $address) {
               <stripped>
              }
            }
            """
        )

        response: GraphQLResponse = await client.query(
            request=request,
            variables={
                'person': person,
                'address': address
            }
        )

        return response.json

Exception:

logger: asyncio

message:
return await self._http_request(
TypeError: 'async with' received an object from __aexit__ that does not implement __await__: type

Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f3de80d3990>
python --version
Python 3.8.5

pip freeze
aiographql-client==1.0.2

uname -a
Linux 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

helpers.py could be like this

import aiohttp


def aiohttp_client_session():
    connector = aiohttp.TCPConnector(
        force_close=True, limit=1, enable_cleanup_closed=True
    )
    return aiohttp.ClientSession(connector=connector)

Can't install it using pip

I'm receiving this error trying to install it

> pip install aiographql-client
ERROR: Could not find a version that satisfies the requirement aiographql-client (from versions: none)
ERROR: No matching distribution found for aiographql-client

Customize Payload on `CONNECTION_INIT`

Originally raised in #166 by @serializingme

Another issue I had was the need to have some extra data on the CONNECTION_INIT payload. I modified the connection_init_request in client\subscription.py:138 to add extra content to the returned dictionary:

return {
    "type": GraphQLSubscriptionEventType.CONNECTION_INIT.value,
    "payload": {**extra_data, "headers": {**self.request.headers}},
}

Add support ujson v4

Hello everyone! Thanks for the great package!

I need support for ujson version 4. My repositories already use version 4.x and I can't install this library because of this.

Installation failed with python 3.11

In a virtualenv: /tmp/venv/bin/pip install "aiographql-client>=1.0.3" gives:

…
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [54 lines of output]
      running egg_info
      writing lib3/PyYAML.egg-info/PKG-INFO
      writing dependency_links to lib3/PyYAML.egg-info/dependency_links.txt
      writing top-level names to lib3/PyYAML.egg-info/top_level.txt
      Traceback (most recent call last):
        File "/tmp/venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/tmp/venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 271, in <module>
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/__init__.py", line 103, in setup
          return distutils.core.setup(**attrs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
                 ^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/dist.py", line 963, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 321, in run
          self.find_sources()
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 329, in find_sources
          mm.run()
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 551, in run
          self.add_defaults()
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 589, in add_defaults
          sdist.add_defaults(self)
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/command/sdist.py", line 112, in add_defaults
          super().add_defaults()
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/_distutils/command/sdist.py", line 251, in add_defaults
          self._add_defaults_ext()
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/_distutils/command/sdist.py", line 336, in _add_defaults_ext
          self.filelist.extend(build_ext.get_source_files())
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "<string>", line 201, in get_source_files
        File "/tmp/pip-build-env-2j9_0ad1/overlay/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 107, in __getattr__
          raise AttributeError(attr)
      AttributeError: cython_sources
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Some issues with the subscriptions handling

Hi,

I have been trying to integrate the library and found some problems. After much debugging 😅 follows the two issues and the solutions I found:

Missing Sec-WebSocket-Protocol Header

When establishing the Web Socket connection to the Apollo server the server will reject the connection without any feedback if the header Sec-WebSocket-Protocol is not provided. The expected value for the header is graphql-ws. I worked around this by modifying the code with (client\subscription.py:201):

headers = {
    'Sec-WebSocket-Protocol': 'graphql-ws'
}

async with session.ws_connect(endpoint, headers=headers) as ws:

Customize Payload on CONNECTION_INIT

Another issue I had was the need to have some extra data on the CONNECTION_INIT payload. I modified the connection_init_request in client\subscription.py:138 to add extra content to the returned dictionary:

return {
    "type": GraphQLSubscriptionEventType.CONNECTION_INIT.value,
    "payload": {**extra_data, "headers": {**self.request.headers}},
}

I would be very thankful if this could be fixed / supported. Let me know if I can help, thank you in advance! 😃

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.