const query1 = `{ user(id: "$id") { * } }` type query1 = `{ user(id: "$id") { * } }` type Result1 = { user: { id: string name: string } } const query2 = `{ posts { } }` type query2 = `{ posts { } }` type Result2 = { posts: { id: string title: string }[] } function $graphql(q: query1, args?: any): Result1 function $graphql(q: query2, args?: any): Result2 function $graphql(q: string, args?: any): any function $graphql( q: query1 | query2 | string, args?: any, ): Result1 | Result2 | any { switch (q) { case query1: return { user: { id: 'xxx', name: 'xxx' } } case query2: return { posts: [{ id: 'xxx', title: 'xxx' }] } default: return '' } } const myRes1 = $graphql( `{ user(id: "$id") { * } }`, { id: 'sfds' }, ) const myRes2 = $query(`{ posts { } }`) const other = $graphql(`xxx`)