2016-03-13 203 views

回答

4

該字符串是操作名稱。如果您未指定名稱,則該操作被稱爲匿名操作。實際上,我總是指定一個操作名稱,因爲它可以讓讀取堆棧跟蹤等操作更輕鬆。

it seems removing this from the string doesn't affect anything

當您執行單個操作時,您只能使用匿名操作。例如,在一個錯誤的結果如下:

query { 
    user(id: 1) { 
    name 
    } 
} 

query { 
    user(id: 2) { 
    name 
    } 
} 

錯誤:

"message": "This anonymous operation must be the only defined operation." 

如果您想了解更多,您可以檢查出the GraphQL spec

If a document contains only one operation, that operation may be unnamed or represented in the shorthand form, which omits both the query keyword and operation name. Otherwise, if a GraphQL query document contains multiple operations, each operation must be named.