How to use the gql.utils_codegen.CodeChunk function in gql

To help you get started, we’ve selected a few gql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphql-python / gql-next / tests / test_utils_codegen.py View on Github external
def test_codegen_write_template_strings_args(module_compiler):
    gen = CodeChunk()
    gen.write('def {0}(a, b):', 'sum')
    gen.indent()
    gen.write('return a + b')

    code = str(gen)

    m = module_compiler(code)
    assert m.sum(2, 3) == 5
github graphql-python / gql-next / tests / test_utils_codegen.py View on Github external
def test_codegen_write_block(module_compiler):
    gen = CodeChunk()
    with gen.write_block('def {name}(a, b):', name='sum'):
        gen.write('return a + b')

    code = str(gen)

    m = module_compiler(code)
    assert m.sum(2, 3) == 5
github graphql-python / gql-next / tests / test_utils_codegen.py View on Github external
def test_codegen_block(module_compiler):
    gen = CodeChunk()
    gen.write('def sum(a, b):')
    with gen.block():
        gen.write('return a + b')

    code = str(gen)

    m = module_compiler(code)
    assert m.sum(2, 3) == 5
github graphql-python / gql-next / tests / test_utils_codegen.py View on Github external
def test_codegen_write_simple_strings(module_compiler):
    gen = CodeChunk()
    gen.write('def sum(a, b):')
    gen.indent()
    gen.write('return a + b')

    code = str(gen)

    m = module_compiler(code)
    assert m.sum(2, 3) == 5
github graphql-python / gql-next / tests / test_utils_codegen.py View on Github external
def test_codegen_write_template_strings_kwargs(module_compiler):
    gen = CodeChunk()
    gen.write('def {method}(a, b):', method='sum')
    gen.indent()
    gen.write('return a + b')

    code = str(gen)

    m = module_compiler(code)
    assert m.sum(2, 3) == 5
github graphql-python / gql-next / tests / test_utils_codegen.py View on Github external
def test_codegen_write_lines(module_compiler):
    lines = [
        '@staticmethod',
        'def sum(a, b):'
        '    return a + b'
    ]
    gen = CodeChunk()
    gen.write('class Math:')
    gen.indent()
    gen.write_lines(lines)

    code = str(gen)

    m = module_compiler(code)
    assert m.Math.sum(2, 3) == 5
github graphql-python / gql-next / gql / renderer_dataclasses.py View on Github external
def render(self, parsed_query: ParsedQuery):
        # We sort fragment nodes to be first and operations to be last because of dependecies
        buffer = CodeChunk()
        buffer.write('# AUTOGENERATED file. Do not Change!')
        buffer.write('from functools import partial')
        buffer.write('from typing import Any, Callable, Mapping, List')
        buffer.write('from enum import Enum')
        buffer.write('from dataclasses import dataclass, field')
        buffer.write('from dataclasses_json import dataclass_json')
        buffer.write('from gql.clients import Client, AsyncIOClient')
        buffer.write('')

        if self.config.custom_header:
            buffer.write_lines(self.config.custom_header.split('\n'))

        buffer.write('')

        self.__render_datetime_field(buffer)