GraphQL 쿼리를 REST 호환 HTTP 요청으로 변환하는 가벼운 Flutter/Dart 라이브러리입니다. 전용 GraphQL 클라이언트 없이도 표준 HTTP 클라이언트를 사용하여 GraphQL 작업을 실행할 수 있게 해줍니다. 기존의 REST 기반 인프라 및 도구와의 통합을 간소화하며, 특히 GraphQL 클라이언트가 사용 불가능하거나 선호되지 않는 환경에서 유용합니다. 이 패키지는 모든 주요 플랫폼을 지원하므로, 유연한 API 통신이 필요한 크로스플랫폼 애플리케이션에 적합합니다.
사용 사례
레거시 시스템을 위한 GraphQL 쿼리에서 REST로 변환
GraphQL 데이터와 표준 HTTP 클라이언트 사용
제약된 환경에서의 API 통합 간소화
엄격한 HTTP 클라이언트 정책을 가진 앱에서 GraphQL 사용 활성화
하이브리드 REST-GraphQL 백엔드 아키텍처 지원
주요 기능
경량이며 최소한의 종속성
GraphQL에서 REST로의 자동 쿼리 변환
크로스 플랫폼 호환성
모든 HTTP 클라이언트와 호환됩니다
pub add 명령을 통한 간단한 통합
적합한 대상
REST 클라이언트를 사용하지만 GraphQL 데이터가 필요한 개발자
REST에서 GraphQL로 점진적으로 이전하는 팀
엄격한 종속성 제약을 가진 프로젝트
다중 플랫폼을 대상으로 하는 애플리케이션
유연한 API 계층 설계가 필요한 사용 사례
고려 사항
기본 GraphQL 쿼리 지원에 제한됨
내장된 오류 처리 또는 캐싱 없음
변경 또는 구독을 지원하지 않습니다
헤더 및 인증의 수동 관리가 필요합니다
복잡한 GraphQL 스키마에는 적합하지 않습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
GraphQL to REST
A lightweight library for converting GraphQL queries into REST format, enabling the use of any HTTP client for executing requests.
Usage
To work effectively with the graphql_2_rest library, you primarily need to use two key components: GraphQLQueryPayload and GraphQLQueryBuilder.
GraphQLQueryPayload is responsible for providing the arguments and input models to be used in a GraphQL query. For example, if you have queries like:
GraphQLQueryBuilder automatically replaces all argument placeholders in the query using values provided by the GraphQLQueryPayload. By default, GraphQLQueryBuilder uses the following prefixes:
% for arguments
@ for input models
These default prefixes can be customized by specifying different values for argumentPrefix and inputPrefix when creating an instance of the class.
After building the query, you can use any HTTP client to perform the request, but keep in mind that the request must use the POST method:
final dio = Dio(BaseOptions(baseUrl: 'https://endpoint/'));
final queryBuilder = GraphQLQueryBuilder(
transformer: (query) => query.replaceAll(RegExp(r'\s+'), ' ').trim(),
);
dio.post<dynamic>(
'graphql/',
data: queryBuilder.build(
queryA, //or queryBUserQueryPayloadA(27, 'John'), //or UserQueryPayloadB(27, 'John')
),
);