Coverage for graphqler / compiler / resolvers / llm / prompt_templates.py: 100%

5 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-18 23:20 -0400

1"""Prompt templates for the LLM-based dependency resolver. 

2 

3These are intentionally kept in a separate module so they can be tuned 

4independently of the resolver logic. 

5""" 

6 

7# ── Schema context ──────────────────────────────────────────────────────────── 

8 

9SCHEMA_CONTEXT_HEADER = "Available GraphQL objects in this API (name: field(type), ...):\n" 

10 

11# ── Mutation resolver prompt ────────────────────────────────────────────────── 

12 

13MUTATION_SYSTEM_PROMPT = """\ 

14You are an expert GraphQL API analyst. Given a GraphQL schema and a list of mutations, \ 

15you infer semantic dependency relationships between mutations and the objects in the schema. 

16You always respond with valid JSON and nothing else.\ 

17""" 

18 

19MUTATION_USER_PROMPT_TEMPLATE = """\ 

20{schema_context} 

21 

22For each mutation listed below, determine: 

231. "mutationType" — classify as one of: 

24 - "CREATE" : the mutation creates / adds / inserts / registers a new resource 

25 - "UPDATE" : the mutation modifies / edits / updates / patches an existing resource 

26 - "DELETE" : the mutation removes / deletes / destroys / deactivates an existing resource 

27 - "UNKNOWN" : cannot be determined with confidence 

28 

292. "hardDependsOn" — a JSON object mapping input-parameter-name → ObjectName for inputs that 

30 are NON_NULL (required) and semantically reference an existing object in the schema. 

31 An input "references" an object when it would only make sense if that object already exists 

32 (e.g. userId references User, userEmail references User, postSlug references Post). 

33 

343. "softDependsOn" — same as hardDependsOn, but for OPTIONAL inputs. 

35 

36Rules: 

37- Only include an input in hardDependsOn / softDependsOn if it references a KNOWN object 

38 from the schema context above. 

39- Use the EXACT object name as it appears in the schema (case-sensitive). 

40- If no inputs reference any objects, use empty objects {{}}. 

41- Do not include scalar-only references that don't relate to a schema object. 

42 

43Mutations to analyse (as simplified JSON — type "T!" means NON_NULL, "[T]" means list): 

44{mutations_json} 

45 

46Respond with a single JSON object. Each key is a mutation name; each value has exactly: 

47 "mutationType": string, 

48 "hardDependsOn": object, 

49 "softDependsOn": object 

50 

51Example: 

52{{ 

53 "createPost": {{"mutationType": "CREATE", "hardDependsOn": {{"authorId": "User"}}, "softDependsOn": {{"tagId": "Tag"}}}}, 

54 "deleteUser": {{"mutationType": "DELETE", "hardDependsOn": {{"id": "User"}}, "softDependsOn": {{}}}} 

55}}\ 

56""" 

57 

58# ── Query resolver prompt ───────────────────────────────────────────────────── 

59 

60QUERY_SYSTEM_PROMPT = """\ 

61You are an expert GraphQL API analyst. Given a GraphQL schema and a list of queries, \ 

62you infer which existing objects each query depends on in order to execute meaningfully. 

63You always respond with valid JSON and nothing else.\ 

64""" 

65 

66QUERY_USER_PROMPT_TEMPLATE = """\ 

67{schema_context} 

68 

69For each query listed below, determine: 

70 

711. "hardDependsOn" — a JSON object mapping input-parameter-name → ObjectName for inputs that 

72 are NON_NULL (required) and semantically reference an existing object in the schema. 

73 

742. "softDependsOn" — same, but for OPTIONAL inputs. 

75 

76Rules: 

77- Only include an input in hardDependsOn / softDependsOn if it references a KNOWN object 

78 from the schema context above. 

79- Use the EXACT object name as it appears in the schema (case-sensitive). 

80- If no inputs reference any objects, use empty objects {{}}. 

81 

82Queries to analyse (as simplified JSON — type "T!" means NON_NULL, "[T]" means list): 

83{queries_json} 

84 

85Respond with a single JSON object. Each key is a query name; each value has exactly: 

86 "hardDependsOn": object, 

87 "softDependsOn": object 

88 

89Example: 

90{{ 

91 "getPost": {{"hardDependsOn": {{"id": "Post"}}, "softDependsOn": {{}}}}, 

92 "listUserPosts": {{"hardDependsOn": {{"userId": "User"}}, "softDependsOn": {{"tagId": "Tag"}}}} 

93}}\ 

94"""