Would it be possible to use Fragments just for pure re-usability? (without forced parent-child component encapsulation)
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start with lib/graphql/client/schema/object_type.rb at the method_missing check that raises ImplicitlyFetchedFieldError, then read lib/graphql/client/response.rb and the linked graphlient fragment example. Define how a query-level fragment should differ from a child-component fragment; done means fields selected through that fragment can be accessed directly without the implicit-fetch error.
Written by the indexing model from the issue text.
Description
In regards to the ImplicitlyFetchedFieldError, that is raised in GraphQL::Client::Schema::ObjectType, on method_missing...
- Here is the line
if @data.key?(field.name)
raise ImplicitlyFetchedFieldError
Would it be possible to have the option to use fragments just for re-usability?
For example, in the Apollo documentation on fragments, it states that
the main reason for fragments to exist is re-usability. It certainly emphasizes that it is specially useful when collocating with components, but it does NOT say that this is the only usage that we should be able to make out of it.
In the documentation (see collocated fragments), somehow states that there are two types of fragments, the ones that are "externally" (or collaterally) referred to by a component, and the ones that are defined right on that component (collated):
A colocated fragment is just like any other fragment, except it's defined in the same file as a particular component that uses the fragment's fields.
After you define a fragment in a child component, the parent component can refer to it in its own colocated fragments, like so:
export const FEED_ENTRY_FRAGMENT = gql`
fragment FeedEntryFragment on FeedEntry {
commentCount
repository {
full_name
html_url
owner {
avatar_url
}
}
...VoteButtonsFragment
...EntryInfoFragment
}
${VOTE_BUTTONS_FRAGMENT}
${ENTRY_INFO_FRAGMENT}
- In this example
VOTE_BUTTONS_FRAGMENTandENTRY_INFO_FRAGMENTare defined in (or imported from) child components.
Apollo's technique to define fragments and identify if they belong to a parent or children classes can arguable, yet they offer a way.
Following the example of graphlient gem, where fragments support was added by making it aligned with graphql-client, in the following query...
module Fragments
Invoice = client.parse <<~'GRAPHQL'
fragment on Invoice {
id
feeInCents
}
GRAPHQL
end
invoice_query = client.parse do
query do
invoice(id: 10) do
id
___Fragments__Invoice
end
end
end
... we would get the error if trying to access feeInCents directly from the query Response
response = client.execute(invoice_query)
result = response.data.invoice
result.to_h
# {"id" => 10, "feeInCents"=> 20000}
result.id
# 10
result.fee_in_cents
# raises GraphQL::Client::ImplicitlyFetchedFieldError
How would we in graphql-client define a fragment that belongs to the main query (or parent component)?
invoice_query <<~'GRAPHQL'
query InvoiceById($some_id: Int) {
invoice(id: $some_id) {
id
...withFee
}
}
fragment withFee on Invoice {
id
feeInCents
}
GRAPHQL
provided that we can do something like this:
response = client.execute(invoice_query)
result = response.data.invoice
result.fee_in_cents
without getting the error GraphQL::Client::ImplicitlyFetchedFieldError.
- Dominant language
- Ruby
- Stars
- 79
- Forks
- 227
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from github-community-projects/graphql-client
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
github-community-projects/graphql-client#78 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
github-community-projects/graphql-client#77 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
github-community-projects/graphql-client#75 · 1 comment · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
github-community-projects/graphql-client#67 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
github-community-projects/graphql-client#65 · 1 comment ·
All issues in github-community-projects/graphql-client
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
OpenAPITools/openapi-generator#25768 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
olivierlacan/trebuche#8 ·
-
chore
Difficulty 1/5 Under an hour Newbie friendliness 84/100
AllYourBot/hostedgpt#929 ·
Maintainers usually reply within 1 day
-
Error toast on about page when domain blocks missingPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
sentry-rails: excluded_exceptions triggers a Rails deprecation warning for ActionController::InvalidAuthenticityTokenPossibly taken A pull request linked to this issue is open or already merged. OpenBug Ruby Waiting for: Product Owner
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
getsentry/sentry-ruby#3228 · 1 comment ·
Maintainers usually reply within 1 day