2017-05-22 5 views

답변

0

예, release 3.0.0부터 가능합니다.

schema { 
    query: QueryType 
} 

type QueryType { 
    hero(episode: Episode): Character 
    human(id : String) : Human 
    droid(id: ID!): Droid 
} 

당신은 을 변환 할 수 다음은이 같은 실행 스키마IDL 파일 (starWarsSchema.graphqls) 다음

SchemaParser schemaParser = new SchemaParser(); 
SchemaGenerator schemaGenerator = new SchemaGenerator(); 

File schemaFile = loadSchema("starWarsSchema.graphqls"); 

TypeDefinitionRegistry typeRegistry = schemaParser.parse(schemaFile); 
RuntimeWiring wiring = buildRuntimeWiring(); 
GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeRegistry, wiring); 

또한 당신은이에 buildRuntime 기능을 구현하는 고정 스키마를 해결 자으로 연결하십시오.

RuntimeWiring buildRuntimeWiring() { 
    return RuntimeWiring.newRuntimeWiring() 
      .scalar(CustomScalar) 
      .type("QueryType", typeWiring -> typeWiring 
        .dataFetcher("hero", new StaticDataFetcher(StarWarsData.getArtoo())) 
        .dataFetcher("human", StarWarsData.getHumanDataFetcher()) 
        .dataFetcher("droid", StarWarsData.getDroidDataFetcher()) 
      ) 
      .build(); 
} 

더 자세한 예는 graphql-java documentation에서 찾을 수 있습니다.

+0

답장을 보내 주셔서 감사합니다. 나도 이것을 시도했지만, Maven 저장소에 제공 한 최신 항아리는 이것을 지원하지 않는다. 나는 이것이 최신 항아리에 누락 된 코드의 일부로 인한 것이라고 생각합니다. ** SchemaGenerator ** 파일은 지원되지 않습니다. 이걸 확인해 주시겠습니까? –

+1

최신 릴리스 3.0.0에서 작동합니다. 이 버전이 있는지 확인하십시오. 아마도 이전에'mvn clean'을 명시 적으로 실행하십시오. –

+0

idl에서 설명과 설명을 사용할 수 있는지 알고있는 사람이 있습니까? – atott