def write_field_docstring(self, field): if not self.docstrings: return lines = [] description = field.get('description') if description: lines.extend(paragraph_wrapper.wrap(description)) args = field.get('args') if args: if lines: lines.append('') lines.extend(paragraph_wrapper.wrap('Arguments:')) lines.append('') for a in args: n = BaseItem._to_python_name(a['name']) t = graphql_type_to_str(a['type']) d = a.get('description', '') if d: d = ': ' + d defval = a.get('defaultValue') if defval is None: defval = '' else: defval = ' (default: `%s`)' % (defval,) lines.extend(list_wrapper.wrap( '`%s` (`%s`)%s%s' % (n, t, d, defval) )) self.writer(to_docstring(lines)) self.writer('\n')
def write_field_input(self, field, siblings): name = field['name'] tref = self.get_type_ref(field['type'], siblings) self.writer('''\ %(py_name)s = sgqlc.types.Field(%(type)s, graphql_name=%(gql_name)r) ''' % { 'py_name': BaseItem._to_python_name(name), 'gql_name': name, 'type': tref, }) self.write_field_docstring(field)
def write_field_output(self, field, siblings): name = field['name'] tref = self.get_type_ref(field['type'], siblings) self.writer('''\ %(py_name)s = sgqlc.types.Field(%(type)s, graphql_name=%(gql_name)r\ ''' % { 'py_name': BaseItem._to_python_name(name), 'gql_name': name, 'type': tref, }) args = field['args'] if args: self.writer(', args=sgqlc.types.ArgDict((\n') for a in args: self.write_arg(a, siblings) self.writer('))\n ') self.writer(')\n') self.write_field_docstring(field)
def write_arg(self, arg, siblings): name = arg['name'] tref = self.get_type_ref(arg['type'], siblings) defval = arg.get('defaultValue') if defval: if defval.startswith('$'): defval = 'sgqlc.types.Variable(%r)' % defval[1:] else: defval = repr(parse_graphql_value_to_json(defval)) self.writer('''\ (%(py_name)r, sgqlc.types.Arg(%(type)s, graphql_name=%(gql_name)r, \ default=%(default)s)), ''' % { 'py_name': BaseItem._to_python_name(name), 'gql_name': name, 'type': tref, 'default': defval, })
def get_py_fields_and_siblings(self, own_fields): graphql_fields = tuple(field['name'] for field in own_fields) py_fields = tuple( BaseItem._to_python_name(f_name) for f_name in graphql_fields ) return py_fields, set(graphql_fields)