Only wait for auth on queries that need it
I switched from my `_NoAuthRequired` opname hack, to a more robust `context` argument, and it's opt-in! This should make queries without user data faster by default. We'll need to remember to specify this in order to get user data, but it shouldn't be something we'd like, ship without remembering—the feature just won't work until we do!
This commit is contained in:
parent
7f777ed5b3
commit
81117218a3
11 changed files with 63 additions and 56 deletions
|
@ -14,7 +14,7 @@ import { ErrorMessage, Heading1 } from "./util";
|
|||
function ConversionPage() {
|
||||
const { loading, error, data } = useQuery(
|
||||
gql`
|
||||
query ConversionPage_NoAuthRequired {
|
||||
query ConversionPage {
|
||||
numAppearanceLayersConverted
|
||||
numAppearanceLayersTotal
|
||||
|
||||
|
|
|
@ -352,7 +352,7 @@ function ItemsSearchField() {
|
|||
function NewItemsSectionContent() {
|
||||
const { loading, error, data } = useQuery(
|
||||
gql`
|
||||
query NewItemsSection_NoAuthRequired {
|
||||
query NewItemsSection {
|
||||
newestItems {
|
||||
id
|
||||
name
|
||||
|
|
|
@ -130,7 +130,7 @@ function ItemPageOwnWantButtons({ itemId }) {
|
|||
}
|
||||
}
|
||||
`,
|
||||
{ variables: { itemId } }
|
||||
{ variables: { itemId }, context: { sendAuth: true } }
|
||||
);
|
||||
|
||||
if (error) {
|
||||
|
@ -171,6 +171,7 @@ function ItemPageOwnButton({ itemId, isChecked }) {
|
|||
`,
|
||||
{
|
||||
variables: { itemId },
|
||||
context: { sendAuth: true },
|
||||
optimisticResponse: {
|
||||
__typename: "Mutation",
|
||||
addToItemsCurrentUserOwns: {
|
||||
|
@ -193,6 +194,7 @@ function ItemPageOwnButton({ itemId, isChecked }) {
|
|||
`,
|
||||
{
|
||||
variables: { itemId },
|
||||
context: { sendAuth: true },
|
||||
optimisticResponse: {
|
||||
__typename: "Mutation",
|
||||
removeFromItemsCurrentUserOwns: {
|
||||
|
@ -279,6 +281,7 @@ function ItemPageWantButton({ itemId, isChecked }) {
|
|||
`,
|
||||
{
|
||||
variables: { itemId },
|
||||
context: { sendAuth: true },
|
||||
optimisticResponse: {
|
||||
__typename: "Mutation",
|
||||
addToItemsCurrentUserWants: {
|
||||
|
@ -301,6 +304,7 @@ function ItemPageWantButton({ itemId, isChecked }) {
|
|||
`,
|
||||
{
|
||||
variables: { itemId },
|
||||
context: { sendAuth: true },
|
||||
optimisticResponse: {
|
||||
__typename: "Mutation",
|
||||
removeFromItemsCurrentUserWants: {
|
||||
|
|
|
@ -130,6 +130,7 @@ function ItemTradesTable({
|
|||
const { isLoggedIn } = useCurrentUser();
|
||||
const { loading, error, data } = useQuery(tradesQuery, {
|
||||
variables: { itemId },
|
||||
context: { sendAuth: true },
|
||||
});
|
||||
|
||||
const shouldShowCompareColumn = isLoggedIn;
|
||||
|
|
|
@ -25,7 +25,8 @@ function ModelingPage() {
|
|||
}
|
||||
|
||||
function ItemModelsSection() {
|
||||
const { loading, error, data } = useQuery(gql`
|
||||
const { loading, error, data } = useQuery(
|
||||
gql`
|
||||
query ModelingPage {
|
||||
standardItems: itemsThatNeedModels {
|
||||
...ItemFields
|
||||
|
@ -73,7 +74,9 @@ function ItemModelsSection() {
|
|||
isNc
|
||||
createdAt
|
||||
}
|
||||
`);
|
||||
`,
|
||||
{ context: { sendAuth: true } }
|
||||
);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
|
|
|
@ -82,7 +82,7 @@ function UserItemsPage() {
|
|||
}
|
||||
}
|
||||
`,
|
||||
{ variables: { userId } }
|
||||
{ variables: { userId }, context: { sendAuth: true } }
|
||||
);
|
||||
|
||||
if (loading) {
|
||||
|
|
|
@ -65,6 +65,7 @@ function UserOutfitsPageContent() {
|
|||
// NOTE: This parameter is used inside `OutfitThumbnailFragment`!
|
||||
size: "SIZE_" + getOutfitThumbnailRenderSize(),
|
||||
},
|
||||
context: { sendAuth: true },
|
||||
skip: userLoading,
|
||||
}
|
||||
);
|
||||
|
|
|
@ -313,6 +313,7 @@ function useSearchResults(query, outfitState) {
|
|||
colorId,
|
||||
offset: 0,
|
||||
},
|
||||
context: { sendAuth: true },
|
||||
skip:
|
||||
!debouncedQuery.value &&
|
||||
!debouncedQuery.filterToItemKind &&
|
||||
|
|
|
@ -154,6 +154,7 @@ function useOutfitState() {
|
|||
`,
|
||||
{
|
||||
variables: { allItemIds, speciesId, colorId },
|
||||
context: { sendAuth: true },
|
||||
// Skip if this outfit has no items, as an optimization; or if we don't
|
||||
// have the species/color ID loaded yet because we're waiting on the
|
||||
// saved outfit to load.
|
||||
|
|
|
@ -142,12 +142,8 @@ const persistedQueryLink = createPersistedQueryLink({
|
|||
});
|
||||
const httpLink = createHttpLink({ uri: "/api/graphql" });
|
||||
const buildAuthLink = (getAuth0) =>
|
||||
setContext(async ({ operationName }, { headers }) => {
|
||||
// Our little hack to decorate queries that don't need auth, and can load
|
||||
// without waiting for it!
|
||||
// TODO: It feels like inverting this might be the better way to go?...
|
||||
const skipAuth = operationName?.includes("_NoAuthRequired");
|
||||
if (skipAuth) {
|
||||
setContext(async (_, { headers = {}, sendAuth = false }) => {
|
||||
if (!sendAuth) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ function SpeciesColorPicker({
|
|||
onChange,
|
||||
}) {
|
||||
const { loading: loadingMeta, error: errorMeta, data: meta } = useQuery(gql`
|
||||
query SpeciesColorPicker_NoAuthRequired {
|
||||
query SpeciesColorPicker {
|
||||
allSpecies {
|
||||
id
|
||||
name
|
||||
|
|
Loading…
Reference in a new issue