"""GraphQL-core based schema parser. Uses graphql-core's parse() to extract queries, mutations, and object types from SDL strings. """ from graphql import parse from graphql.language.ast import ( ObjectTypeDefinitionNode, ObjectTypeExtensionNode, ) SKIP_TYPES = {'Subscription'} def parse_sdl(sdl: str) -> tuple[set[str], set[str], dict[str, set[str]]]: """Parse an SDL string and extract queries, mutations, and object types. Returns: queries: set of field names on type Query mutations: set of field names on type Mutation objects: {typeName: set(fieldNames)} for object types (excluding Query/Mutation/interfaces) """ queries: set[str] = set() mutations: set[str] = set() objects: dict[str, set[str]] = {} document = parse(sdl) for definition in document.definitions: if not isinstance(definition, (ObjectTypeDefinitionNode, ObjectTypeExtensionNode)): continue type_name = definition.name.value if type_name.startswith('_') or type_name in SKIP_TYPES: continue field_names = set() for field in definition.fields or []: name = field.name.value if not name.startswith('_'): field_names.add(name) if type_name == 'Query': queries.update(field_names) elif type_name == 'Mutation': mutations.update(field_names) else: if type_name not in objects: objects[type_name] = set() objects[type_name].update(field_names) return queries, mutations, objects