-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with null value in referenced document #702
Comments
|
Sure here it is: This is the site settings schema import { Settings2Icon } from 'lucide-react'
// import { defineField, defineType } from 'sanity'
import { defineField, defineType } from '@sanity-typed/types'
export const siteSettingsType = defineType({
name: 'siteSettings',
title: 'Site settings',
type: 'document',
icon: Settings2Icon,
groups: [
{
name: 'general',
title: 'General',
},
{
name: 'seo',
title: 'Global SEO',
},
{
name: 'assistant',
title: 'AI assistant',
},
],
fields: [
defineField({
name: 'title',
type: 'string',
validation: (Rule) => Rule.required(),
}),
defineField({
name: 'description',
type: 'text',
rows: 5,
}),
defineField({
title: 'AI assistant',
name: 'assistant',
type: 'reference',
to: [{ type: 'assistant' as const }],
group: ['assistant'],
}),
defineField({
title: 'SEO Title',
name: 'seoTitle',
type: 'string',
group: 'seo',
}),
defineField({
title: 'SEO Meta description',
name: 'seoMetaDescription',
type: 'text',
rows: 5,
group: 'seo',
}),
defineField({
title: 'SEO Meta image',
name: 'seoMetaImage',
type: 'image',
options: {
hotspot: true,
},
group: 'seo',
}),
],
preview: {
select: {
title: 'title',
subtitle: 'instructions',
},
},
}) the assistant schema is import { BotIcon } from 'lucide-react'
// import { defineField, defineType } from 'sanity'
import { defineField, defineType } from '@sanity-typed/types'
export const assistantType = defineType({
name: 'assistant',
title: 'AI Assistant',
type: 'document',
icon: BotIcon,
groups: [
{
name: 'advanced',
title: 'Advanced',
},
{
name: 'persona',
title: 'Persona',
},
],
fields: [
defineField({
name: 'title',
type: 'string',
}),
defineField({
name: 'model',
type: 'string',
options: {
list: [
{ title: 'GPT-3.5-TURBO', value: 'gpt-3.5-turbo' },
{ title: 'GPT-4-TURBO-PREVIEW', value: 'gpt-4-turbo-preview' },
{ title: 'GPT-4', value: 'gpt-4' },
],
},
initialValue: 'gpt-3.5-turbo',
}),
defineField({
name: 'instructions',
type: 'text',
rows: 5,
group: 'persona',
}),
defineField({
name: 'temperature',
type: 'number',
initialValue: 0.2,
validation: (rule) => rule.required().min(0).max(1).precision(1),
group: 'advanced',
}),
{
title: 'Functions',
name: 'functions',
type: 'array',
of: [
{
type: 'string',
options: {
list: [
{ title: 'Google places', value: 'google-places-api' },
{ title: 'Google Directions', value: 'google-directions-api' },
{ title: 'Tavily search', value: 'tavily-search' },
{ title: 'Exa search', value: 'exa-search' },
{ title: 'Search API', value: 'search-api' }
],
},
},
],
group: 'advanced',
},
],
preview: {
select: {
title: 'title',
subtitle: 'model',
},
},
}) The query I am making is
Client defined as import { createClient } from '@sanity-typed/client'
import { apiVersion, dataset, projectId } from '~/sanity/projectDetails'
import type { SanityValues } from 'sanity.config'
export const client = createClient<SanityValues>({
projectId,
dataset,
apiVersion,
useCdn: true,
perspective: 'published',
}) Sanity.config.ts import { visionTool } from '@sanity/vision'
// import { defineConfig } from 'sanity'
import { InferSchemaValues, defineConfig } from '@sanity-typed/types'
import { structureTool } from 'sanity/structure'
import { projectDetails } from '~/sanity/projectDetails'
import schema from '~/sanity/schema'
import { defaultDocumentNode, structure } from '~/sanity/structure'
export const config = defineConfig({
...projectDetails(),
name: 'sanity-remix',
title: 'Sanity Remix',
plugins: [
structureTool({
structure: structure,
defaultDocumentNode: defaultDocumentNode,
}),
visionTool(),
],
basePath: `/studio`,
schema: {
types: schema,
},
})
export type SanityValues = InferSchemaValues<typeof config> Now when making the query as:
The return type is defined as: const getCurrentAssistant: () => Promise<{
assistant: {
temperature: null;
model: null;
functions: null;
instructions: null;
};
}> Which is not the correct return type, though type definitions are there, but individual fields are not... For 2, when making the query as import groq from 'groq'
export const ASSISTANT_QUERY = groq`*[_type == "siteSettings" && _id == "siteSettings"][0]{
assistant -> {
temperature,
model,
functions,
instructions
}
}` The return type is not even typed, as you said you haven't factored this in, but just for clarity, the return type is: const getCurrentAssistant: () => Promise<never> |
null
type instead beingstring | null
type.import groq from 'groq'
using the GROQ tagged template literal, I am getting a response asPromise<never>
instead of being typed, Is this the intended behaviorThe text was updated successfully, but these errors were encountered: