108 lines
2.7 KiB
Python
108 lines
2.7 KiB
Python
import json
|
|
import requests
|
|
|
|
class RSCGraphQL:
|
|
def __init__(self, auth):
|
|
self.auth = auth
|
|
self.endpoint = f"https://{self.auth.host}/api/graphql"
|
|
|
|
def query(self, query, variables=None):
|
|
payload = {'query': query}
|
|
if variables:
|
|
payload['variables'] = variables
|
|
|
|
headers = self.auth.get_headers()
|
|
response = requests.post(self.endpoint, json=payload, headers=headers)
|
|
response.raise_for_status()
|
|
|
|
data = response.json()
|
|
|
|
# Check for GraphQL errors
|
|
if 'errors' in data:
|
|
raise Exception(f"GraphQL errors: {data['errors']}")
|
|
|
|
return data
|
|
|
|
def introspect_schema(self):
|
|
"""Introspect the GraphQL schema to get type information"""
|
|
introspection_query = """
|
|
query IntrospectionQuery {
|
|
__schema {
|
|
types {
|
|
name
|
|
kind
|
|
description
|
|
fields(includeDeprecated: true) {
|
|
name
|
|
description
|
|
type {
|
|
name
|
|
kind
|
|
ofType {
|
|
name
|
|
kind
|
|
}
|
|
}
|
|
args {
|
|
name
|
|
description
|
|
type {
|
|
name
|
|
kind
|
|
ofType {
|
|
name
|
|
kind
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
return self.query(introspection_query)
|
|
|
|
def get_type_info(self, type_name):
|
|
"""Get detailed information about a specific GraphQL type"""
|
|
query = """
|
|
query GetTypeInfo($typeName: String!) {
|
|
__type(name: $typeName) {
|
|
name
|
|
kind
|
|
description
|
|
fields(includeDeprecated: true) {
|
|
name
|
|
description
|
|
type {
|
|
name
|
|
kind
|
|
ofType {
|
|
name
|
|
kind
|
|
ofType {
|
|
name
|
|
kind
|
|
}
|
|
}
|
|
}
|
|
args {
|
|
name
|
|
description
|
|
type {
|
|
name
|
|
kind
|
|
ofType {
|
|
name
|
|
kind
|
|
ofType {
|
|
name
|
|
kind
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
return self.query(query, {"typeName": type_name}) |