---
title: "JSS GraphQL辞書サービスで辞書データを取得"
slug: "fetch-dictionary-data-with-the-jss-graphql-dictionary-service"
abstract: "JSS GraphQL辞書サービスで辞書データを取得する方法Sitecore例。"
---
# JSS GraphQL辞書サービスで辞書データを取得

GraphQLとJSSGraphQLDictionaryServiceを使ってSitecoreから辞書データを取得できます。 

> !注この例は、アプリケーションのルートディレクトリにファイルを作成し、同じディレクトリにconfig.jsファイルがあることを前提としています。プロジェクトのセットアップに合わせてインポート文を調整してください。

JSS GraphQL辞書サービスで辞書データを取得するには:

1.  dictionary-service.tsファイルで、GraphQLDictionaryServiceのインスタンスを作成・設定します:
    
    import {GraphQLDictionaryService} from '@sitecore-jss/sitecore-jss';
    import config from './config';
    
    export const dictionaryService = new GraphQLDictionaryService({
     endpoint: config.graphQLEndpoint,
     apiKey: config.sitecoreApiKey,
     siteName: config.jssAppName,
     /\*
     The Dictionary Service needs a root item ID to fetch dictionary phrases for the current
     app. If your Sitecore instance only has 1 JSS App, you can specify the root item ID here;
     otherwise, the service will attempt to figure out the root item for the current JSS App using GraphQL and app name.
     rootItemId: '{GUID}'
     \*/
    });
    
2.  データを取得したいファイルで、新しい辞書サービスインスタンスをインポートして使用してください:
    
    import { dictionaryService } from './dictionary-service';
    const language = 'en';
    dictionaryService.fetchDictionaryData(language).then(data => {
     // do something with the data
    });