Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use fragments in graphql server schema file

Can you use fragments in graphql server schema file? Could you please point me to an example

like image 670
user3732317 Avatar asked Jan 23 '18 05:01

user3732317


People also ask

What other types can be used in a GraphQL schema?

The GraphQL schema language supports the scalar types of String , Int , Float , Boolean , and ID , so you can use these directly in the schema you pass to buildSchema . By default, every type is nullable - it's legitimate to return null as any of the scalar types.

How do Fragments work in GraphQL?

A GraphQL fragment is a piece of logic that can be shared between multiple queries and mutations. Every fragment includes a subset of the fields that belong to its associated type. In the above example, the Person type must declare firstName and lastName fields for the NameParts fragment to be valid.

How do you import fragments in GraphQL?

You can use the function exported from @graphql-fragment-import/lib/inline-imports to combine all the fragment definitions imported directly and transitively in a graphql file. In the code example above, fileContents is the source code of a . graphql file.

When would you use a GraphQL fragment?

A GraphQL fragment is a reusable part of the query. In GraphQL, you may run into situations where you need to query for the same fields in different queries. If you notice that your query has many repetitive fields in multiple areas, you can consolidate them into a reusable unit called a fragment.


1 Answers

No. Fragments are defined for operations (queries) only. If what you're looking for is to reuse a bunch of definitions, I'm afraid you're constrained to implementing an interface, or just good ol' composition. Most implementations also support type extensions, graphql-java certainly does.

like image 120
kaqqao Avatar answered Sep 30 '22 05:09

kaqqao