2016-06-13 6 views
3

未定義私はGraphQLエラー - 引数の型が入力型ではなくなっている必要があります。

export const getPicture = { 
    type: GraphPicture, 
    args: { 
     type: new GraphQLNonNull(GraphQLInt) 
    }, 
    resolve(_, args) { 
     return Picture.findByPrimary(args.id); 
    } 
}; 

export const getPictureList = { 
    type: new GraphQLList(GraphPicture), 
    resolve(_, __, session) { 
     return Picture.findAll({where: {owner: session.userId}}); 
    } 
}; 

とスロー

const query = new GraphQLObjectType({ 
    name: 'Queries', 
    fields:() => { 
     return { 
      getPictureList: getPictureList, 
      getPicture: getPicture 
     } 
    } 
}); 

const schema = new GraphQLSchema({ 
    query: query, 
    mutation: mutation 
}); 

あります

Error: Queries.getPicture(type:) argument type must be Input Type but got: undefined. 

getPictureListが正常に動作しますが、getPictureは失敗します。

私は助けにはならない、getPicture GraphQLLIstを作るしようとしています。

私は助けにならない、引数が入力タイプを入力することを試みました。

何が起こっているかについての任意のアイデアがここに

スタックトレースは次のとおりです。

Error: Queries.getPicture(type:) argument type must be Input Type but got: undefined. 
at invariant (/home/jrootham/dev/trytheseon/node_modules/graphql/jsutils/invariant.js:19:11) 
at /home/jrootham/dev/trytheseon/node_modules/graphql/type/definition.js:307:33 
at Array.map (native) 
at /home/jrootham/dev/trytheseon/node_modules/graphql/type/definition.js:304:52 
at Array.forEach (native) 
at defineFieldMap (/home/jrootham/dev/trytheseon/node_modules/graphql/type/definition.js:293:14) 
at GraphQLObjectType.getFields (/home/jrootham/dev/trytheseon/node_modules/graphql/type/definition.js:250:46) 
at /home/jrootham/dev/trytheseon/node_modules/graphql/type/schema.js:224:27 
at typeMapReducer (/home/jrootham/dev/trytheseon/node_modules/graphql/type/schema.js:236:7) 
at Array.reduce (native) 
at new GraphQLSchema (/home/jrootham/dev/trytheseon/node_modules/graphql/type/schema.js:104:34) 
at Object.<anonymous> (/home/jrootham/dev/trytheseon/server/graphQL.js:45:16) 
at Module._compile (module.js:399:26) 
at normalLoader (/usr/lib/node_modules/babel/node_modules/babel-core/lib/babel/api/register/node.js:160:5) 
at Object.require.extensions.(anonymous function) [as .js] (/usr/lib/node_modules/babel/node_modules/babel-core/lib/babel/api/register/node.js:173:7) 
at Module.load (module.js:345:32) 
at Function.Module._load (module.js:302:12) 
at Module.require (module.js:355:17) 
at require (internal/module.js:13:17) 
at Object.<anonymous> (/home/jrootham/dev/trytheseon/devServer.js:14:44) 
at Module._compile (module.js:399:26) 
at normalLoader (/usr/lib/node_modules/babel/node_modules/babel-core/lib/babel/api/register/node.js:160:5) 
+0

わからないが、それは関連だ場合、しかし、あなただけのタイプを指定し、トンに思えますo引数名(id)が欠けている。 – helfer

+0

@OP、ルートクエリで 'getPicture'をパラメータ化。異なるメモでは、 'getPicture'の代わりに' picture'という名前を付けることを検討するかもしれません。それはもっと慣例です。クエリを経由してスキーマ定義に渡さ –

+0

@AhmadFerdousクエリがparamertizedする必要はありません、彼らは渡されるパラメータは、自分自身を呼び出します。 –

答えて

9

問題は、クエリの戻り値の型がありますが、あなたの引数に指定したタイプではありません。

export const getPicture = { 
    type: GraphPicture, 
    args: { 
     type: new GraphQLNonNull(GraphQLInt) 
    }, 
    resolve(_, args) { 
     return Picture.findByPrimary(args.id); 
    } 
}; 

あなたが名前付き引数を持っているためのものと仮定し、 "タイプ" は、それは次のようになります。

hero: { 
    type: characterInterface, 
    args: { 
    episode: { 
     description: 'If omitted, returns the hero of the whole saga. If ' + 
        'provided, returns the hero of that particular episode.', 
     type: episodeEnum 
    } 
    }, 
    resolve: (root, { episode }) => getHero(episode), 
}, 

がフルを参照してください:ここ

export const getPicture = { 
    type: GraphPicture, 
    args: { 
     type: { 
      type: new GraphQLNonNull(GraphQLInt) 
     } 
    }, 
    resolve(_, args) { 
     return Picture.findByPrimary(args.id); 
    } 
}; 

がgraphql-jsのレポの例でありますここgraphql-jsのレポからスキーマ: https://github.com/graphql/graphql-js/blob/master/src/tests/starWarsSchema.js

関連する問題