id
int64
1
6.07M
name
stringlengths
1
295
code
stringlengths
12
426k
language
stringclasses
1 value
source_file
stringlengths
5
202
start_line
int64
1
158k
end_line
int64
1
158k
repo
dict
5,601
do_types_overlap
def do_types_overlap(schema, t1, t2): # print 'do_types_overlap', t1, t2 if t1 == t2: # print '1' return True if isinstance(t1, (GraphQLInterfaceType, GraphQLUnionType)): if isinstance(t2, (GraphQLInterfaceType, GraphQLUnionType)): # If both types are abstract, then determine if there is any intersection # between possible concrete types of each. s = any([schema.is_possible_type(t2, type) for type in schema.get_possible_types(t1)]) # print '2',s return s # Determine if the latter type is a possible concrete type of the former. r = schema.is_possible_type(t1, t2) # print '3', r return r if isinstance(t2, (GraphQLInterfaceType, GraphQLUnionType)): t = schema.is_possible_type(t2, t1) # print '4', t return t # print '5' return False
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_comparators.py
45
69
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,602
_false
def _false(*_): return False
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
17
18
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,603
_none
def _none(*_): return None
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
21
22
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,604
no_execution
def no_execution(*args): raise Exception('Client Schema cannot be used for execution.')
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
25
26
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,605
build_client_schema
def build_client_schema(introspection): schema_introspection = introspection['__schema'] type_introspection_map = {t['name']: t for t in schema_introspection['types']} type_def_cache = { 'String': GraphQLString, 'Int': GraphQLInt, 'Float': GraphQLFloat, 'Boolean': GraphQLBoolean, 'ID': GraphQLID, '__Schema': __Schema, '__Directive': __Directive, '__DirectiveLocation': __DirectiveLocation, '__Type': __Type, '__Field': __Field, '__InputValue': __InputValue, '__EnumValue': __EnumValue, '__TypeKind': __TypeKind, } def get_type(type_ref): kind = type_ref.get('kind') if kind == TypeKind.LIST: item_ref = type_ref.get('ofType') if not item_ref: raise Exception('Decorated type deeper than introspection query.') return GraphQLList(get_type(item_ref)) elif kind == TypeKind.NON_NULL: nullable_ref = type_ref.get('ofType') if not nullable_ref: raise Exception('Decorated type deeper than introspection query.') return GraphQLNonNull(get_type(nullable_ref)) return get_named_type(type_ref['name']) def get_named_type(type_name): if type_name in type_def_cache: return type_def_cache[type_name] type_introspection = type_introspection_map.get(type_name) if not type_introspection: raise Exception( 'Invalid or incomplete schema, unknown type: {}. Ensure that a full introspection query ' 'is used in order to build a client schema.'.format(type_name) ) type_def = type_def_cache[type_name] = build_type(type_introspection) return type_def def get_input_type(type_ref): input_type = get_type(type_ref) assert is_input_type(input_type), 'Introspection must provide input type for arguments.' return input_type def get_output_type(type_ref): output_type = get_type(type_ref) assert is_output_type(output_type), 'Introspection must provide output type for fields.' return output_type def get_object_type(type_ref): object_type = get_type(type_ref) assert isinstance(object_type, GraphQLObjectType), 'Introspection must provide object type for possibleTypes.' return object_type def get_interface_type(type_ref): interface_type = get_type(type_ref) assert isinstance(interface_type, GraphQLInterfaceType), \ 'Introspection must provide interface type for interfaces.' return interface_type def build_type(type): type_kind = type.get('kind') handler = type_builders.get(type_kind) if not handler: raise Exception( 'Invalid or incomplete schema, unknown kind: {}. Ensure that a full introspection query ' 'is used in order to build a client schema.'.format(type_kind) ) return handler(type) def build_scalar_def(scalar_introspection): return GraphQLScalarType( name=scalar_introspection['name'], description=scalar_introspection.get('description'), serialize=_none, parse_value=_false, parse_literal=_false ) def build_object_def(object_introspection): return GraphQLObjectType( name=object_introspection['name'], description=object_introspection.get('description'), interfaces=[get_interface_type(i) for i in object_introspection.get('interfaces', [])], fields=lambda: build_field_def_map(object_introspection) ) def build_interface_def(interface_introspection): return GraphQLInterfaceType( name=interface_introspection['name'], description=interface_introspection.get('description'), fields=lambda: build_field_def_map(interface_introspection), resolve_type=no_execution ) def build_union_def(union_introspection): return GraphQLUnionType( name=union_introspection['name'], description=union_introspection.get('description'), types=[get_object_type(t) for t in union_introspection.get('possibleTypes', [])], resolve_type=no_execution ) def build_enum_def(enum_introspection): return GraphQLEnumType( name=enum_introspection['name'], description=enum_introspection.get('description'), values=OrderedDict([(value_introspection['name'], GraphQLEnumValue(description=value_introspection.get('description'), deprecation_reason=value_introspection.get('deprecationReason'))) for value_introspection in enum_introspection.get('enumValues', []) ]) ) def build_input_object_def(input_object_introspection): return GraphQLInputObjectType( name=input_object_introspection['name'], description=input_object_introspection.get('description'), fields=lambda: build_input_value_def_map( input_object_introspection.get('inputFields'), GraphQLInputObjectField ) ) type_builders = { TypeKind.SCALAR: build_scalar_def, TypeKind.OBJECT: build_object_def, TypeKind.INTERFACE: build_interface_def, TypeKind.UNION: build_union_def, TypeKind.ENUM: build_enum_def, TypeKind.INPUT_OBJECT: build_input_object_def } def build_field_def_map(type_introspection): return OrderedDict([ (f['name'], GraphQLField( type=get_output_type(f['type']), description=f.get('description'), resolver=no_execution, deprecation_reason=f.get('deprecationReason'), args=build_input_value_def_map(f.get('args'), GraphQLArgument))) for f in type_introspection.get('fields', []) ]) def build_default_value(f): default_value = f.get('defaultValue') if default_value is None: return None return value_from_ast(parse_value(default_value), get_input_type(f['type'])) def build_input_value_def_map(input_value_introspection, argument_type): return OrderedDict([ (f['name'], build_input_value(f, argument_type)) for f in input_value_introspection ]) def build_input_value(input_value_introspection, argument_type): input_value = argument_type( description=input_value_introspection['description'], type=get_input_type(input_value_introspection['type']), default_value=build_default_value(input_value_introspection) ) return input_value def build_directive(directive_introspection): # Support deprecated `on****` fields for building `locations`, as this # is used by GraphiQL which may need to support outdated servers. locations = list(directive_introspection.get('locations', [])) if not locations: locations = [] if directive_introspection.get('onField', False): locations += list(DirectiveLocation.FIELD_LOCATIONS) if directive_introspection.get('onOperation', False): locations += list(DirectiveLocation.OPERATION_LOCATIONS) if directive_introspection.get('onFragment', False): locations += list(DirectiveLocation.FRAGMENT_LOCATIONS) return GraphQLDirective( name=directive_introspection['name'], description=directive_introspection.get('description'), # TODO: {} ? args=build_input_value_def_map(directive_introspection.get('args', {}), GraphQLArgument), locations=locations ) # Iterate through all types, getting the type definition for each, ensuring # that any type not directly referenced by a field will get created. types = [get_named_type(type_introspection_name) for type_introspection_name in type_introspection_map.keys()] query_type = get_object_type(schema_introspection['queryType']) mutation_type = get_object_type( schema_introspection['mutationType']) if schema_introspection.get('mutationType') else None subscription_type = get_object_type(schema_introspection['subscriptionType']) if \ schema_introspection.get('subscriptionType') else None directives = [build_directive(d) for d in schema_introspection['directives']] \ if schema_introspection['directives'] else [] return GraphQLSchema( query=query_type, mutation=mutation_type, subscription=subscription_type, directives=directives, types=types )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
29
250
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,606
get_type
def get_type(type_ref): kind = type_ref.get('kind') if kind == TypeKind.LIST: item_ref = type_ref.get('ofType') if not item_ref: raise Exception('Decorated type deeper than introspection query.') return GraphQLList(get_type(item_ref)) elif kind == TypeKind.NON_NULL: nullable_ref = type_ref.get('ofType') if not nullable_ref: raise Exception('Decorated type deeper than introspection query.') return GraphQLNonNull(get_type(nullable_ref)) return get_named_type(type_ref['name'])
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
51
69
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,607
get_named_type
def get_named_type(type_name): if type_name in type_def_cache: return type_def_cache[type_name] type_introspection = type_introspection_map.get(type_name) if not type_introspection: raise Exception( 'Invalid or incomplete schema, unknown type: {}. Ensure that a full introspection query ' 'is used in order to build a client schema.'.format(type_name) ) type_def = type_def_cache[type_name] = build_type(type_introspection) return type_def
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
71
83
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,608
get_input_type
def get_input_type(type_ref): input_type = get_type(type_ref) assert is_input_type(input_type), 'Introspection must provide input type for arguments.' return input_type
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
85
88
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,609
get_output_type
def get_output_type(type_ref): output_type = get_type(type_ref) assert is_output_type(output_type), 'Introspection must provide output type for fields.' return output_type
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
90
93
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,610
get_object_type
def get_object_type(type_ref): object_type = get_type(type_ref) assert isinstance(object_type, GraphQLObjectType), 'Introspection must provide object type for possibleTypes.' return object_type
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
95
98
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,611
get_interface_type
def get_interface_type(type_ref): interface_type = get_type(type_ref) assert isinstance(interface_type, GraphQLInterfaceType), \ 'Introspection must provide interface type for interfaces.' return interface_type
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
100
104
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,612
build_type
def build_type(type): type_kind = type.get('kind') handler = type_builders.get(type_kind) if not handler: raise Exception( 'Invalid or incomplete schema, unknown kind: {}. Ensure that a full introspection query ' 'is used in order to build a client schema.'.format(type_kind) ) return handler(type)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
106
115
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,613
build_scalar_def
def build_scalar_def(scalar_introspection): return GraphQLScalarType( name=scalar_introspection['name'], description=scalar_introspection.get('description'), serialize=_none, parse_value=_false, parse_literal=_false )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
117
124
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,614
build_object_def
def build_object_def(object_introspection): return GraphQLObjectType( name=object_introspection['name'], description=object_introspection.get('description'), interfaces=[get_interface_type(i) for i in object_introspection.get('interfaces', [])], fields=lambda: build_field_def_map(object_introspection) )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
126
132
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,615
build_interface_def
def build_interface_def(interface_introspection): return GraphQLInterfaceType( name=interface_introspection['name'], description=interface_introspection.get('description'), fields=lambda: build_field_def_map(interface_introspection), resolve_type=no_execution )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
134
140
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,616
build_union_def
def build_union_def(union_introspection): return GraphQLUnionType( name=union_introspection['name'], description=union_introspection.get('description'), types=[get_object_type(t) for t in union_introspection.get('possibleTypes', [])], resolve_type=no_execution )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
142
148
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,617
build_enum_def
def build_enum_def(enum_introspection): return GraphQLEnumType( name=enum_introspection['name'], description=enum_introspection.get('description'), values=OrderedDict([(value_introspection['name'], GraphQLEnumValue(description=value_introspection.get('description'), deprecation_reason=value_introspection.get('deprecationReason'))) for value_introspection in enum_introspection.get('enumValues', []) ]) )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
150
159
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,618
build_input_object_def
def build_input_object_def(input_object_introspection): return GraphQLInputObjectType( name=input_object_introspection['name'], description=input_object_introspection.get('description'), fields=lambda: build_input_value_def_map( input_object_introspection.get('inputFields'), GraphQLInputObjectField ) )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
161
168
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,619
build_field_def_map
def build_field_def_map(type_introspection): return OrderedDict([ (f['name'], GraphQLField( type=get_output_type(f['type']), description=f.get('description'), resolver=no_execution, deprecation_reason=f.get('deprecationReason'), args=build_input_value_def_map(f.get('args'), GraphQLArgument))) for f in type_introspection.get('fields', []) ])
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
179
188
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,620
build_default_value
def build_default_value(f): default_value = f.get('defaultValue') if default_value is None: return None return value_from_ast(parse_value(default_value), get_input_type(f['type']))
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
190
195
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,621
build_input_value_def_map
def build_input_value_def_map(input_value_introspection, argument_type): return OrderedDict([ (f['name'], build_input_value(f, argument_type)) for f in input_value_introspection ])
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
197
200
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,622
build_input_value
def build_input_value(input_value_introspection, argument_type): input_value = argument_type( description=input_value_introspection['description'], type=get_input_type(input_value_introspection['type']), default_value=build_default_value(input_value_introspection) ) return input_value
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
202
208
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,623
build_directive
def build_directive(directive_introspection): # Support deprecated `on****` fields for building `locations`, as this # is used by GraphiQL which may need to support outdated servers. locations = list(directive_introspection.get('locations', [])) if not locations: locations = [] if directive_introspection.get('onField', False): locations += list(DirectiveLocation.FIELD_LOCATIONS) if directive_introspection.get('onOperation', False): locations += list(DirectiveLocation.OPERATION_LOCATIONS) if directive_introspection.get('onFragment', False): locations += list(DirectiveLocation.FRAGMENT_LOCATIONS) return GraphQLDirective( name=directive_introspection['name'], description=directive_introspection.get('description'), # TODO: {} ? args=build_input_value_def_map(directive_introspection.get('args', {}), GraphQLArgument), locations=locations )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py
210
229
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,624
ast_to_dict
def ast_to_dict(node, include_loc=False): if isinstance(node, Node): d = { 'kind': node.__class__.__name__ } if hasattr(node, '_fields'): for field in node._fields: d[field] = ast_to_dict(getattr(node, field), include_loc) if include_loc and hasattr(node, 'loc') and node.loc: d['loc'] = { 'start': node.loc.start, 'end': node.loc.end } return d elif isinstance(node, list): return [ast_to_dict(item, include_loc) for item in node] return node
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_dict.py
4
24
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,625
_build_wrapped_type
def _build_wrapped_type(inner_type, input_type_ast): if isinstance(input_type_ast, ast.ListType): return GraphQLList(_build_wrapped_type(inner_type, input_type_ast.type)) if isinstance(input_type_ast, ast.NonNullType): return GraphQLNonNull(_build_wrapped_type(inner_type, input_type_ast.type)) return inner_type
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
19
26
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,626
_get_inner_type_name
def _get_inner_type_name(type_ast): if isinstance(type_ast, (ast.ListType, ast.NonNullType)): return _get_inner_type_name(type_ast.type) return type_ast.name.value
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
29
33
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,627
_get_named_type_ast
def _get_named_type_ast(type_ast): named_type = type_ast while isinstance(named_type, (ast.ListType, ast.NonNullType)): named_type = named_type.type return named_type
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
36
41
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,628
_false
def _false(*_): return False
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
44
45
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,629
_none
def _none(*_): return None
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
48
49
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,630
build_ast_schema
def build_ast_schema(document): assert isinstance(document, ast.Document), 'must pass in Document ast.' schema_def = None type_asts = ( ast.ScalarTypeDefinition, ast.ObjectTypeDefinition, ast.InterfaceTypeDefinition, ast.EnumTypeDefinition, ast.UnionTypeDefinition, ast.InputObjectTypeDefinition, ) type_defs = [] directive_defs = [] for d in document.definitions: if isinstance(d, ast.SchemaDefinition): if schema_def: raise Exception('Must provide only one schema definition.') schema_def = d if isinstance(d, type_asts): type_defs.append(d) elif isinstance(d, ast.DirectiveDefinition): directive_defs.append(d) if not schema_def: raise Exception('Must provide a schema definition.') query_type_name = None mutation_type_name = None subscription_type_name = None for operation_type in schema_def.operation_types: type_name = operation_type.type.name.value if operation_type.operation == 'query': if query_type_name: raise Exception('Must provide only one query type in schema.') query_type_name = type_name elif operation_type.operation == 'mutation': if mutation_type_name: raise Exception('Must provide only one mutation type in schema.') mutation_type_name = type_name elif operation_type.operation == 'subscription': if subscription_type_name: raise Exception('Must provide only one subscription type in schema.') subscription_type_name = type_name if not query_type_name: raise Exception('Must provide schema definition with query type.') ast_map = {d.name.value: d for d in type_defs} if query_type_name not in ast_map: raise Exception('Specified query type "{}" not found in document.'.format(query_type_name)) if mutation_type_name and mutation_type_name not in ast_map: raise Exception('Specified mutation type "{}" not found in document.'.format(mutation_type_name)) if subscription_type_name and subscription_type_name not in ast_map: raise Exception('Specified subscription type "{}" not found in document.'.format(subscription_type_name)) inner_type_map = OrderedDict([ ('String', GraphQLString), ('Int', GraphQLInt), ('Float', GraphQLFloat), ('Boolean', GraphQLBoolean), ('ID', GraphQLID), ('__Schema', __Schema), ('__Directive', __Directive), ('__DirectiveLocation', __DirectiveLocation), ('__Type', __Type), ('__Field', __Field), ('__InputValue', __InputValue), ('__EnumValue', __EnumValue), ('__TypeKind', __TypeKind), ]) def get_directive(directive_ast): return GraphQLDirective( name=directive_ast.name.value, locations=[node.value for node in directive_ast.locations], args=make_input_values(directive_ast.arguments, GraphQLArgument), ) def get_object_type(type_ast): type = type_def_named(type_ast.name.value) assert isinstance(type, GraphQLObjectType), 'AST must provide object type' return type def produce_type_def(type_ast): type_name = _get_named_type_ast(type_ast).name.value type_def = type_def_named(type_name) return _build_wrapped_type(type_def, type_ast) def type_def_named(type_name): if type_name in inner_type_map: return inner_type_map[type_name] if type_name not in ast_map: raise Exception('Type "{}" not found in document'.format(type_name)) inner_type_def = make_schema_def(ast_map[type_name]) if not inner_type_def: raise Exception('Nothing constructed for "{}".'.format(type_name)) inner_type_map[type_name] = inner_type_def return inner_type_def def make_schema_def(definition): if not definition: raise Exception('def must be defined.') handler = _schema_def_handlers.get(type(definition)) if not handler: raise Exception('Type kind "{}" not supported.'.format(type(definition).__name__)) return handler(definition) def make_type_def(definition): return GraphQLObjectType( name=definition.name.value, fields=lambda: make_field_def_map(definition), interfaces=make_implemented_interfaces(definition) ) def make_field_def_map(definition): return OrderedDict( (f.name.value, GraphQLField( type=produce_type_def(f.type), args=make_input_values(f.arguments, GraphQLArgument), deprecation_reason=get_deprecation_reason(f.directives), )) for f in definition.fields ) def make_implemented_interfaces(definition): return [produce_type_def(i) for i in definition.interfaces] def make_input_values(values, cls): return OrderedDict( (value.name.value, cls( type=produce_type_def(value.type), default_value=value_from_ast(value.default_value, produce_type_def(value.type)) )) for value in values ) def make_interface_def(definition): return GraphQLInterfaceType( name=definition.name.value, resolve_type=_none, fields=lambda: make_field_def_map(definition) ) def make_enum_def(definition): values = OrderedDict((v.name.value, GraphQLEnumValue(deprecation_reason=get_deprecation_reason(v.directives))) for v in definition.values) return GraphQLEnumType( name=definition.name.value, values=values ) def make_union_def(definition): return GraphQLUnionType( name=definition.name.value, resolve_type=_none, types=[produce_type_def(t) for t in definition.types] ) def make_scalar_def(definition): return GraphQLScalarType( name=definition.name.value, serialize=_none, # Validation calls the parse functions to determine if a literal value is correct. # Returning none, however would cause the scalar to fail validation. Returning false, # will cause them to pass. parse_literal=_false, parse_value=_false ) def make_input_object_def(definition): return GraphQLInputObjectType( name=definition.name.value, fields=make_input_values(definition.fields, GraphQLInputObjectField) ) _schema_def_handlers = { ast.ObjectTypeDefinition: make_type_def, ast.InterfaceTypeDefinition: make_interface_def, ast.EnumTypeDefinition: make_enum_def, ast.UnionTypeDefinition: make_union_def, ast.ScalarTypeDefinition: make_scalar_def, ast.InputObjectTypeDefinition: make_input_object_def } types = [type_def_named(definition.name.value) for definition in type_defs] directives = [get_directive(d) for d in directive_defs] # If specified directive were not explicitly declared, add them. find_skip_directive = (directive.name for directive in directives if directive.name == 'skip') find_include_directive = (directive.name for directive in directives if directive.name == 'include') find_deprecated_directive = (directive.name for directive in directives if directive.name == 'deprecated') if not next(find_skip_directive, None): directives.append(GraphQLSkipDirective) if not next(find_include_directive, None): directives.append(GraphQLIncludeDirective) if not next(find_deprecated_directive, None): directives.append(GraphQLDeprecatedDirective) schema_kwargs = {'query': get_object_type(ast_map[query_type_name])} if mutation_type_name: schema_kwargs['mutation'] = get_object_type(ast_map[mutation_type_name]) if subscription_type_name: schema_kwargs['subscription'] = get_object_type(ast_map[subscription_type_name]) if directive_defs: schema_kwargs['directives'] = directives if types: schema_kwargs['types'] = types return GraphQLSchema(**schema_kwargs)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
52
279
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,631
get_directive
def get_directive(directive_ast): return GraphQLDirective( name=directive_ast.name.value, locations=[node.value for node in directive_ast.locations], args=make_input_values(directive_ast.arguments, GraphQLArgument), )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
131
136
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,632
get_object_type
def get_object_type(type_ast): type = type_def_named(type_ast.name.value) assert isinstance(type, GraphQLObjectType), 'AST must provide object type' return type
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
138
141
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,633
produce_type_def
def produce_type_def(type_ast): type_name = _get_named_type_ast(type_ast).name.value type_def = type_def_named(type_name) return _build_wrapped_type(type_def, type_ast)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
143
146
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,634
type_def_named
def type_def_named(type_name): if type_name in inner_type_map: return inner_type_map[type_name] if type_name not in ast_map: raise Exception('Type "{}" not found in document'.format(type_name)) inner_type_def = make_schema_def(ast_map[type_name]) if not inner_type_def: raise Exception('Nothing constructed for "{}".'.format(type_name)) inner_type_map[type_name] = inner_type_def return inner_type_def
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
148
160
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,635
make_schema_def
def make_schema_def(definition): if not definition: raise Exception('def must be defined.') handler = _schema_def_handlers.get(type(definition)) if not handler: raise Exception('Type kind "{}" not supported.'.format(type(definition).__name__)) return handler(definition)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
162
170
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,636
make_type_def
def make_type_def(definition): return GraphQLObjectType( name=definition.name.value, fields=lambda: make_field_def_map(definition), interfaces=make_implemented_interfaces(definition) )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
172
177
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,637
make_field_def_map
def make_field_def_map(definition): return OrderedDict( (f.name.value, GraphQLField( type=produce_type_def(f.type), args=make_input_values(f.arguments, GraphQLArgument), deprecation_reason=get_deprecation_reason(f.directives), )) for f in definition.fields )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
179
187
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,638
make_implemented_interfaces
def make_implemented_interfaces(definition): return [produce_type_def(i) for i in definition.interfaces]
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
189
190
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,639
make_input_values
def make_input_values(values, cls): return OrderedDict( (value.name.value, cls( type=produce_type_def(value.type), default_value=value_from_ast(value.default_value, produce_type_def(value.type)) )) for value in values )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
192
199
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,640
make_interface_def
def make_interface_def(definition): return GraphQLInterfaceType( name=definition.name.value, resolve_type=_none, fields=lambda: make_field_def_map(definition) )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
201
206
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,641
make_enum_def
def make_enum_def(definition): values = OrderedDict((v.name.value, GraphQLEnumValue(deprecation_reason=get_deprecation_reason(v.directives))) for v in definition.values) return GraphQLEnumType( name=definition.name.value, values=values )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
208
214
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,642
make_union_def
def make_union_def(definition): return GraphQLUnionType( name=definition.name.value, resolve_type=_none, types=[produce_type_def(t) for t in definition.types] )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
216
221
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,643
make_scalar_def
def make_scalar_def(definition): return GraphQLScalarType( name=definition.name.value, serialize=_none, # Validation calls the parse functions to determine if a literal value is correct. # Returning none, however would cause the scalar to fail validation. Returning false, # will cause them to pass. parse_literal=_false, parse_value=_false )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
223
232
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,644
make_input_object_def
def make_input_object_def(definition): return GraphQLInputObjectType( name=definition.name.value, fields=make_input_values(definition.fields, GraphQLInputObjectField) )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
234
238
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,645
get_deprecation_reason
def get_deprecation_reason(directives): deprecated_ast = next((directive for directive in directives if directive.name.value == GraphQLDeprecatedDirective.name), None) if deprecated_ast: args = get_argument_values(GraphQLDeprecatedDirective.args, deprecated_ast.arguments) return args['reason'] else: return None
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py
282
291
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,646
concat_ast
def concat_ast(asts): return Document(definitions=list(itertools.chain.from_iterable( document.definitions for document in asts )))
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/concat_ast.py
6
9
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,647
extend_schema
def extend_schema(schema, documentAST=None): """Produces a new schema given an existing schema and a document which may contain GraphQL type extensions and definitions. The original schema will remain unaltered. Because a schema represents a graph of references, a schema cannot be extended without effectively making an entire copy. We do not know until it's too late if subgraphs remain unchanged. This algorithm copies the provided schema, applying extensions while producing the copy. The original schema remains unaltered.""" assert isinstance( schema, GraphQLSchema), 'Must provide valid GraphQLSchema' assert documentAST and isinstance( documentAST, ast.Document), 'Must provide valid Document AST' # Collect the type definitions and extensions found in the document. type_definition_map = {} type_extensions_map = defaultdict(list) for _def in documentAST.definitions: if isinstance(_def, ( ast.ObjectTypeDefinition, ast.InterfaceTypeDefinition, ast.EnumTypeDefinition, ast.UnionTypeDefinition, ast.ScalarTypeDefinition, ast.InputObjectTypeDefinition, )): # Sanity check that none of the defined types conflict with the # schema's existing types. type_name = _def.name.value if schema.get_type(type_name): raise GraphQLError( ('Type "{}" already exists in the schema. It cannot also ' + 'be defined in this type definition.').format(type_name), [_def] ) type_definition_map[type_name] = _def elif isinstance(_def, ast.TypeExtensionDefinition): # Sanity check that this type extension exists within the # schema's existing types. extended_type_name = _def.definition.name.value existing_type = schema.get_type(extended_type_name) if not existing_type: raise GraphQLError( ('Cannot extend type "{}" because it does not ' + 'exist in the existing schema.').format(extended_type_name), [_def.definition] ) if not isinstance(existing_type, GraphQLObjectType): raise GraphQLError( 'Cannot extend non-object type "{}".'.format( extended_type_name), [_def.definition] ) type_extensions_map[extended_type_name].append(_def) # Below are functions used for producing this schema that have closed over # this scope and have access to the schema, cache, and newly defined types. def get_type_from_def(type_def): type = _get_named_type(type_def.name) assert type, 'Invalid schema' return type def get_type_from_AST(astNode): type = _get_named_type(astNode.name.value) if not type: raise GraphQLError( ('Unknown type: "{}". Ensure that this type exists ' + 'either in the original schema, or is added in a type definition.').format( astNode.name.value), [astNode] ) return type # Given a name, returns a type from either the existing schema or an # added type. def _get_named_type(typeName): cached_type_def = type_def_cache.get(typeName) if cached_type_def: return cached_type_def existing_type = schema.get_type(typeName) if existing_type: type_def = extend_type(existing_type) type_def_cache[typeName] = type_def return type_def type_ast = type_definition_map.get(typeName) if type_ast: type_def = build_type(type_ast) type_def_cache[typeName] = type_def return type_def # Given a type's introspection result, construct the correct # GraphQLType instance. def extend_type(type): if isinstance(type, GraphQLObjectType): return extend_object_type(type) if isinstance(type, GraphQLInterfaceType): return extend_interface_type(type) if isinstance(type, GraphQLUnionType): return extend_union_type(type) return type def extend_object_type(type): return GraphQLObjectType( name=type.name, description=type.description, interfaces=lambda: extend_implemented_interfaces(type), fields=lambda: extend_field_map(type), ) def extend_interface_type(type): return GraphQLInterfaceType( name=type.name, description=type.description, fields=lambda: extend_field_map(type), resolve_type=cannot_execute_client_schema, ) def extend_union_type(type): return GraphQLUnionType( name=type.name, description=type.description, types=list(map(get_type_from_def, type.types)), resolve_type=cannot_execute_client_schema, ) def extend_implemented_interfaces(type): interfaces = list(map(get_type_from_def, type.interfaces)) # If there are any extensions to the interfaces, apply those here. extensions = type_extensions_map[type.name] for extension in extensions: for namedType in extension.definition.interfaces: interface_name = namedType.name.value if any([_def.name == interface_name for _def in interfaces]): raise GraphQLError( ('Type "{}" already implements "{}". ' + 'It cannot also be implemented in this type extension.').format( type.name, interface_name), [namedType] ) interfaces.append(get_type_from_AST(namedType)) return interfaces def extend_field_map(type): new_field_map = OrderedDict() old_field_map = type.fields for field_name, field in old_field_map.items(): new_field_map[field_name] = GraphQLField( extend_field_type(field.type), description=field.description, deprecation_reason=field.deprecation_reason, args=field.args, resolver=cannot_execute_client_schema, ) # If there are any extensions to the fields, apply those here. extensions = type_extensions_map[type.name] for extension in extensions: for field in extension.definition.fields: field_name = field.name.value if field_name in old_field_map: raise GraphQLError( ('Field "{}.{}" already exists in the ' + 'schema. It cannot also be defined in this type extension.').format( type.name, field_name), [field] ) new_field_map[field_name] = GraphQLField( build_field_type(field.type), args=build_input_values(field.arguments), resolver=cannot_execute_client_schema, ) return new_field_map def extend_field_type(type): if isinstance(type, GraphQLList): return GraphQLList(extend_field_type(type.of_type)) if isinstance(type, GraphQLNonNull): return GraphQLNonNull(extend_field_type(type.of_type)) return get_type_from_def(type) def build_type(type_ast): _type_build = { ast.ObjectTypeDefinition: build_object_type, ast.InterfaceTypeDefinition: build_interface_type, ast.UnionTypeDefinition: build_union_type, ast.ScalarTypeDefinition: build_scalar_type, ast.EnumTypeDefinition: build_enum_type, ast.InputObjectTypeDefinition: build_input_object_type } func = _type_build.get(type(type_ast)) if func: return func(type_ast) def build_object_type(type_ast): return GraphQLObjectType( type_ast.name.value, interfaces=lambda: build_implemented_interfaces(type_ast), fields=lambda: build_field_map(type_ast), ) def build_interface_type(type_ast): return GraphQLInterfaceType( type_ast.name.value, fields=lambda: build_field_map(type_ast), resolve_type=cannot_execute_client_schema, ) def build_union_type(type_ast): return GraphQLUnionType( type_ast.name.value, types=list(map(get_type_from_AST, type_ast.types)), resolve_type=cannot_execute_client_schema, ) def build_scalar_type(type_ast): return GraphQLScalarType( type_ast.name.value, serialize=lambda *args, **kwargs: None, # Note: validation calls the parse functions to determine if a # literal value is correct. Returning null would cause use of custom # scalars to always fail validation. Returning false causes them to # always pass validation. parse_value=lambda *args, **kwargs: False, parse_literal=lambda *args, **kwargs: False, ) def build_enum_type(type_ast): return GraphQLEnumType( type_ast.name.value, values={v.name.value: GraphQLEnumValue() for v in type_ast.values}, ) def build_input_object_type(type_ast): return GraphQLInputObjectType( type_ast.name.value, fields=lambda: build_input_values( type_ast.fields, GraphQLInputObjectField), ) def build_implemented_interfaces(type_ast): return list(map(get_type_from_AST, type_ast.interfaces)) def build_field_map(type_ast): return { field.name.value: GraphQLField( build_field_type(field.type), args=build_input_values(field.arguments), resolver=cannot_execute_client_schema, ) for field in type_ast.fields } def build_input_values(values, input_type=GraphQLArgument): input_values = OrderedDict() for value in values: type = build_field_type(value.type) input_values[value.name.value] = input_type( type, default_value=value_from_ast(value.default_value, type) ) return input_values def build_field_type(type_ast): if isinstance(type_ast, ast.ListType): return GraphQLList(build_field_type(type_ast.type)) if isinstance(type_ast, ast.NonNullType): return GraphQLNonNull(build_field_type(type_ast.type)) return get_type_from_AST(type_ast) # If this document contains no new types, then return the same unmodified # GraphQLSchema instance. if not type_extensions_map and not type_definition_map: return schema # A cache to use to store the actual GraphQLType definition objects by name. # Initialize to the GraphQL built in scalars and introspection types. All # functions below are inline so that this type def cache is within the scope # of the closure. type_def_cache = { 'String': GraphQLString, 'Int': GraphQLInt, 'Float': GraphQLFloat, 'Boolean': GraphQLBoolean, 'ID': GraphQLID, '__Schema': __Schema, '__Directive': __Directive, '__DirectiveLocation': __DirectiveLocation, '__Type': __Type, '__Field': __Field, '__InputValue': __InputValue, '__EnumValue': __EnumValue, '__TypeKind': __TypeKind, } # Get the root Query, Mutation, and Subscription types. query_type = get_type_from_def(schema.get_query_type()) existing_mutation_type = schema.get_mutation_type() mutationType = existing_mutation_type and get_type_from_def( existing_mutation_type) or None existing_subscription_type = schema.get_subscription_type() subscription_type = existing_subscription_type and get_type_from_def( existing_subscription_type) or None # Iterate through all types, getting the type definition for each, ensuring # that any type not directly referenced by a field will get created. types = [get_type_from_def(_def) for _def in schema.get_type_map().values()] # Do the same with new types, appending to the list of defined types. types += [get_type_from_AST(_def) for _def in type_definition_map.values()] # Then produce and return a Schema with these types. return GraphQLSchema( query=query_type, mutation=mutationType, subscription=subscription_type, # Copy directives. directives=schema.get_directives(), types=types )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
21
353
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,648
get_type_from_def
def get_type_from_def(type_def): type = _get_named_type(type_def.name) assert type, 'Invalid schema' return type
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
85
88
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,649
get_type_from_AST
def get_type_from_AST(astNode): type = _get_named_type(astNode.name.value) if not type: raise GraphQLError( ('Unknown type: "{}". Ensure that this type exists ' + 'either in the original schema, or is added in a type definition.').format( astNode.name.value), [astNode] ) return type
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
90
99
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,650
_get_named_type
def _get_named_type(typeName): cached_type_def = type_def_cache.get(typeName) if cached_type_def: return cached_type_def existing_type = schema.get_type(typeName) if existing_type: type_def = extend_type(existing_type) type_def_cache[typeName] = type_def return type_def type_ast = type_definition_map.get(typeName) if type_ast: type_def = build_type(type_ast) type_def_cache[typeName] = type_def return type_def
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
103
118
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,651
extend_type
def extend_type(type): if isinstance(type, GraphQLObjectType): return extend_object_type(type) if isinstance(type, GraphQLInterfaceType): return extend_interface_type(type) if isinstance(type, GraphQLUnionType): return extend_union_type(type) return type
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
122
129
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,652
extend_object_type
def extend_object_type(type): return GraphQLObjectType( name=type.name, description=type.description, interfaces=lambda: extend_implemented_interfaces(type), fields=lambda: extend_field_map(type), )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
131
137
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,653
extend_interface_type
def extend_interface_type(type): return GraphQLInterfaceType( name=type.name, description=type.description, fields=lambda: extend_field_map(type), resolve_type=cannot_execute_client_schema, )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
139
145
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,654
extend_union_type
def extend_union_type(type): return GraphQLUnionType( name=type.name, description=type.description, types=list(map(get_type_from_def, type.types)), resolve_type=cannot_execute_client_schema, )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
147
153
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,655
extend_implemented_interfaces
def extend_implemented_interfaces(type): interfaces = list(map(get_type_from_def, type.interfaces)) # If there are any extensions to the interfaces, apply those here. extensions = type_extensions_map[type.name] for extension in extensions: for namedType in extension.definition.interfaces: interface_name = namedType.name.value if any([_def.name == interface_name for _def in interfaces]): raise GraphQLError( ('Type "{}" already implements "{}". ' + 'It cannot also be implemented in this type extension.').format( type.name, interface_name), [namedType] ) interfaces.append(get_type_from_AST(namedType)) return interfaces
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
155
172
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,656
extend_field_map
def extend_field_map(type): new_field_map = OrderedDict() old_field_map = type.fields for field_name, field in old_field_map.items(): new_field_map[field_name] = GraphQLField( extend_field_type(field.type), description=field.description, deprecation_reason=field.deprecation_reason, args=field.args, resolver=cannot_execute_client_schema, ) # If there are any extensions to the fields, apply those here. extensions = type_extensions_map[type.name] for extension in extensions: for field in extension.definition.fields: field_name = field.name.value if field_name in old_field_map: raise GraphQLError( ('Field "{}.{}" already exists in the ' + 'schema. It cannot also be defined in this type extension.').format( type.name, field_name), [field] ) new_field_map[field_name] = GraphQLField( build_field_type(field.type), args=build_input_values(field.arguments), resolver=cannot_execute_client_schema, ) return new_field_map
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
174
204
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,657
extend_field_type
def extend_field_type(type): if isinstance(type, GraphQLList): return GraphQLList(extend_field_type(type.of_type)) if isinstance(type, GraphQLNonNull): return GraphQLNonNull(extend_field_type(type.of_type)) return get_type_from_def(type)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
206
211
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,658
build_type
def build_type(type_ast): _type_build = { ast.ObjectTypeDefinition: build_object_type, ast.InterfaceTypeDefinition: build_interface_type, ast.UnionTypeDefinition: build_union_type, ast.ScalarTypeDefinition: build_scalar_type, ast.EnumTypeDefinition: build_enum_type, ast.InputObjectTypeDefinition: build_input_object_type } func = _type_build.get(type(type_ast)) if func: return func(type_ast)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
213
224
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,659
build_object_type
def build_object_type(type_ast): return GraphQLObjectType( type_ast.name.value, interfaces=lambda: build_implemented_interfaces(type_ast), fields=lambda: build_field_map(type_ast), )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
226
231
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,660
build_interface_type
def build_interface_type(type_ast): return GraphQLInterfaceType( type_ast.name.value, fields=lambda: build_field_map(type_ast), resolve_type=cannot_execute_client_schema, )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
233
238
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,661
build_union_type
def build_union_type(type_ast): return GraphQLUnionType( type_ast.name.value, types=list(map(get_type_from_AST, type_ast.types)), resolve_type=cannot_execute_client_schema, )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
240
245
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,662
build_scalar_type
def build_scalar_type(type_ast): return GraphQLScalarType( type_ast.name.value, serialize=lambda *args, **kwargs: None, # Note: validation calls the parse functions to determine if a # literal value is correct. Returning null would cause use of custom # scalars to always fail validation. Returning false causes them to # always pass validation. parse_value=lambda *args, **kwargs: False, parse_literal=lambda *args, **kwargs: False, )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
247
257
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,663
build_enum_type
def build_enum_type(type_ast): return GraphQLEnumType( type_ast.name.value, values={v.name.value: GraphQLEnumValue() for v in type_ast.values}, )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
259
263
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,664
build_input_object_type
def build_input_object_type(type_ast): return GraphQLInputObjectType( type_ast.name.value, fields=lambda: build_input_values( type_ast.fields, GraphQLInputObjectField), )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
265
270
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,665
build_implemented_interfaces
def build_implemented_interfaces(type_ast): return list(map(get_type_from_AST, type_ast.interfaces))
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
272
273
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,666
build_field_map
def build_field_map(type_ast): return { field.name.value: GraphQLField( build_field_type(field.type), args=build_input_values(field.arguments), resolver=cannot_execute_client_schema, ) for field in type_ast.fields }
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
275
282
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,667
build_input_values
def build_input_values(values, input_type=GraphQLArgument): input_values = OrderedDict() for value in values: type = build_field_type(value.type) input_values[value.name.value] = input_type( type, default_value=value_from_ast(value.default_value, type) ) return input_values
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
284
292
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,668
build_field_type
def build_field_type(type_ast): if isinstance(type_ast, ast.ListType): return GraphQLList(build_field_type(type_ast.type)) if isinstance(type_ast, ast.NonNullType): return GraphQLNonNull(build_field_type(type_ast.type)) return get_type_from_AST(type_ast)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
294
299
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,669
cannot_execute_client_schema
def cannot_execute_client_schema(*args, **kwargs): raise Exception('Client Schema cannot be used for execution.')
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py
356
357
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,670
quoted_or_list
def quoted_or_list(items): '''Given [ A, B, C ] return '"A", "B" or "C"'.''' selected = items[:MAX_LENGTH] quoted_items = ('"{}"'.format(t) for t in selected) def quoted_or_text(text, quoted_and_index): index = quoted_and_index[0] quoted_item = quoted_and_index[1] text += ((', ' if len(selected) > 2 and not index == len(selected) - 1 else ' ') + ('or ' if index == len(selected) - 1 else '') + quoted_item) return text enumerated_items = enumerate(quoted_items) first_item = next(enumerated_items)[1] return functools.reduce(quoted_or_text, enumerated_items, first_item)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/quoted_or_list.py
6
21
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,671
quoted_or_text
def quoted_or_text(text, quoted_and_index): index = quoted_and_index[0] quoted_item = quoted_and_index[1] text += ((', ' if len(selected) > 2 and not index == len(selected) - 1 else ' ') + ('or ' if index == len(selected) - 1 else '') + quoted_item) return text
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/quoted_or_list.py
11
17
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,672
type_from_ast
def type_from_ast(schema, input_type_ast): if isinstance(input_type_ast, ast.ListType): inner_type = type_from_ast(schema, input_type_ast.type) if inner_type: return GraphQLList(inner_type) else: return None if isinstance(input_type_ast, ast.NonNullType): inner_type = type_from_ast(schema, input_type_ast.type) if inner_type: return GraphQLNonNull(inner_type) else: return None assert isinstance(input_type_ast, ast.NamedType), 'Must be a type name.' return schema.get_type(input_type_ast.name.value)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_from_ast.py
5
21
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,673
print_schema
def print_schema(schema): return _print_filtered_schema(schema, lambda n: not(is_spec_directive(n)), _is_defined_type)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
9
10
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,674
print_introspection_schema
def print_introspection_schema(schema): return _print_filtered_schema(schema, is_spec_directive, _is_introspection_type)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
13
14
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,675
is_spec_directive
def is_spec_directive(directive_name): return directive_name in ('skip', 'include', 'deprecated')
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
17
18
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,676
_is_defined_type
def _is_defined_type(typename): return not _is_introspection_type(typename) and not _is_builtin_scalar(typename)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
21
22
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,677
_is_introspection_type
def _is_introspection_type(typename): return typename.startswith('__')
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
25
26
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,678
_is_builtin_scalar
def _is_builtin_scalar(typename): return typename in _builtin_scalars
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
32
33
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,679
_print_filtered_schema
def _print_filtered_schema(schema, directive_filter, type_filter): return '\n\n'.join([ _print_schema_definition(schema) ] + [ _print_directive(directive) for directive in schema.get_directives() if directive_filter(directive.name) ] + [ _print_type(type) for typename, type in sorted(schema.get_type_map().items()) if type_filter(typename) ]) + '\n'
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
36
47
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,680
_print_schema_definition
def _print_schema_definition(schema): operation_types = [] query_type = schema.get_query_type() if query_type: operation_types.append(' query: {}'.format(query_type)) mutation_type = schema.get_mutation_type() if mutation_type: operation_types.append(' mutation: {}'.format(mutation_type)) subscription_type = schema.get_subscription_type() if subscription_type: operation_types.append(' subscription: {}'.format(subscription_type)) return 'schema {{\n{}\n}}'.format('\n'.join(operation_types))
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
50
65
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,681
_print_type
def _print_type(type): if isinstance(type, GraphQLScalarType): return _print_scalar(type) elif isinstance(type, GraphQLObjectType): return _print_object(type) elif isinstance(type, GraphQLInterfaceType): return _print_interface(type) elif isinstance(type, GraphQLUnionType): return _print_union(type) elif isinstance(type, GraphQLEnumType): return _print_enum(type) assert isinstance(type, GraphQLInputObjectType) return _print_input_object(type)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
68
85
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,682
_print_scalar
def _print_scalar(type): return 'scalar {}'.format(type.name)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
88
89
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,683
_print_object
def _print_object(type): interfaces = type.interfaces implemented_interfaces = \ ' implements {}'.format(', '.join(i.name for i in interfaces)) if interfaces else '' return ( 'type {}{} {{\n' '{}\n' '}}' ).format(type.name, implemented_interfaces, _print_fields(type))
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
92
101
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,684
_print_interface
def _print_interface(type): return ( 'interface {} {{\n' '{}\n' '}}' ).format(type.name, _print_fields(type))
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
104
109
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,685
_print_union
def _print_union(type): return 'union {} = {}'.format(type.name, ' | '.join(str(t) for t in type.types))
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
112
113
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,686
_print_enum
def _print_enum(type): return ( 'enum {} {{\n' '{}\n' '}}' ).format(type.name, '\n'.join(' ' + v.name + _print_deprecated(v) for v in type.values))
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
116
121
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,687
_print_input_object
def _print_input_object(type): return ( 'input {} {{\n' '{}\n' '}}' ).format(type.name, '\n'.join(' ' + _print_input_value(name, field) for name, field in type.fields.items()))
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
124
129
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,688
_print_fields
def _print_fields(type): return '\n'.join(' {}{}: {}{}'.format(f_name, _print_args(f), f.type, _print_deprecated(f)) for f_name, f in type.fields.items())
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
132
134
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,689
_print_deprecated
def _print_deprecated(field_or_enum_value): reason = field_or_enum_value.deprecation_reason if reason is None: return '' elif reason in ('', DEFAULT_DEPRECATION_REASON): return ' @deprecated' else: return ' @deprecated(reason: {})'.format(print_ast(ast_from_value(reason)))
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
137
145
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,690
_print_args
def _print_args(field_or_directives): if not field_or_directives.args: return '' return '({})'.format(', '.join(_print_input_value(arg_name, arg) for arg_name, arg in field_or_directives.args.items()))
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
148
152
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,691
_print_input_value
def _print_input_value(name, arg): if arg.default_value is not None: default_value = ' = ' + print_ast(ast_from_value(arg.default_value, arg.type)) else: default_value = '' return '{}: {}{}'.format(name, arg.type, default_value)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
155
161
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,692
_print_directive
def _print_directive(directive): return 'directive @{}{} on {}'.format(directive.name, _print_args(directive), ' | '.join(directive.locations))
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py
164
165
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,693
ast_to_code
def ast_to_code(ast, indent=0): """ Converts an ast into a python code representation of the AST. """ code = [] def append(line): code.append((' ' * indent) + line) if isinstance(ast, Node): append('ast.{}('.format(ast.__class__.__name__)) indent += 1 for i, k in enumerate(ast._fields, 1): v = getattr(ast, k) append('{}={},'.format( k, ast_to_code(v, indent), )) if ast.loc: append('loc={}'.format(ast_to_code(ast.loc, indent))) indent -= 1 append(')') elif isinstance(ast, Loc): append('loc({}, {})'.format(ast.start, ast.end)) elif isinstance(ast, list): if ast: append('[') indent += 1 for i, it in enumerate(ast, 1): is_last = i == len(ast) append(ast_to_code(it, indent) + (',' if not is_last else '')) indent -= 1 append(']') else: append('[]') else: append(repr(ast)) return '\n'.join(code).strip()
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_code.py
5
49
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,694
append
def append(line): code.append((' ' * indent) + line)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_code.py
11
12
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,695
parse
def parse(source, **kwargs): """Given a GraphQL source, parses it into a Document.""" options = {'no_location': False, 'no_source': False} options.update(kwargs) source_obj = source if isinstance(source, str): source_obj = Source(source) parser = Parser(source_obj, options) return parse_document(parser)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/language/parser.py
9
19
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,696
parse_value
def parse_value(source, **kwargs): options = {'no_location': False, 'no_source': False} options.update(kwargs) source_obj = source if isinstance(source, str): source_obj = Source(source) parser = Parser(source_obj, options) return parse_value_literal(parser, False)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/language/parser.py
22
31
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,697
__init__
def __init__(self, source, options): self.lexer = Lexer(source) self.source = source self.options = options self.prev_end = 0 self.token = self.lexer.next_token()
python
wandb/vendor/graphql-core-1.1/wandb_graphql/language/parser.py
37
42
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,698
__init__
def __init__(self, start, end, source=None): self.start = start self.end = end self.source = source
python
wandb/vendor/graphql-core-1.1/wandb_graphql/language/parser.py
48
51
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,699
__repr__
def __repr__(self): source = ' source={}'.format(self.source) if self.source else '' return '<Loc start={} end={}{}>'.format(self.start, self.end, source)
python
wandb/vendor/graphql-core-1.1/wandb_graphql/language/parser.py
53
55
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,700
__eq__
def __eq__(self, other): return ( isinstance(other, Loc) and self.start == other.start and self.end == other.end and self.source == other.source )
python
wandb/vendor/graphql-core-1.1/wandb_graphql/language/parser.py
57
63
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }