简体   繁体   中英

GraphQL - define a schema and query with default return fields

Is there a way to define a schema or query with default return fields?

I would like to returm certain fields when no fields are requested.
Is there a way to return all fields from the source (maybe using *)

So, I've been trying to play with the Schema, the returned GraphQLObjectType and the resolver of it and couldn't find a practical way to achieve what you were looking for.

What i ended up with was defining was defining an extra general field that by the query 的额外常规字段

something like :

{
    people{
         generic
    }
}

when generic 's resolver just returns an object containing all of the type's fields..

While this does not meet what you were looking for, this is what I was able to come up with after being unable to find an answer in google nor stack.

Would be glad to hear an alternative :)

I met the same problem, my solution was to use a middleware that adds to the client query requested fields (generic for example) before graphql perform query execution. Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM